链接:https://docs.microsoft.com/en-us/previous-versions/aspnet/bb514968(v=vs.100)
本主题说明如何在Web服务器上配置ASP.NET配置文件服务,以使其可供使用Windows Communication Foundation(WCF)的客户端使用。该主题还说明了如何执行以下任务:
将ASP.NET配置文件服务配置为WCF服务
如果您还没有ASP.NET Web应用程序,请创建一个。 将WCF服务文件(.svc)文件添加到包含以下指令的Web站点以引用ProfileService类:
在services元素中定义端点契约,在behaviors元素中定义服务行为。在端点协定中包含bindingNamespace属性,如下面的示例所示,以防止某些代理生成工具中出现异常。有关WCF端点的更多信息,请参见Windows通信基础终结点。https://docs.microsoft.com/zh-cn/dotnet/framework/wcf/feature-details/wcf-services-and-aspnet
<system.serviceModel> <services> <service name="System.Web.ApplicationServices.ProfileService" behaviorConfiguration="MyServiceTypeBehaviors"> <endpoint contract= "System.Web.ApplicationServices.ProfileService" binding="basicHttpBinding" bindingNamespace="http://asp.net/ApplicationServices/v200"/> </service> </services> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> </system.serviceModel>
启用配置文件服务并公开属性 如果尚未为Web应用程序定义配置文件属性,请在Web.config文件中定义它们。 以下示例显示了两个配置文件属性的定义。
<system.web.extensions> <scripting> <webServices> <profileService enabled="true" readAccessProperties="Birthday, FavoriteColor" writeAccessProperties="Birthday, FavoriteColor" > </webServices> </scripting> </system.web.extensions>
如果在配置文件属性中保存敏感数据,请通过安全套接字层(SSL,使用HTTPS协议)访问配置文件服务。还要确保数据安全存储。有关更多信息,请参阅保护配置文件属性。有关如何设置WCF服务以通过SSL运行的详细信息,请参阅传输安全性。有关如何设置SSL的详细信息,请参阅Microsoft网站上的配置安全套接字层(IIS 6.0操作指南)和在IIS 7.0中配置安全套接字层。