我已经构建了一个相当简单的WCF服务,该服务托管在IIS 7.5实例上。我已经完成了必要的步骤来保护ssl证书以启用https。我已经解决了所有各种DNS设置,因此现在可以从世界各地的给定Https:// URL进入WCF了。目标是:为大约5个将向该服务发送数据的客户端进行某种客户端/服务器身份验证。确保这项服务的最佳方法是什么?此时,只有一种方法非常简单。我确定web.config以及背后的代码都会有所变化。实例不胜感激。
这是Web.config
<!-- language: lang-xml -->
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="wcflistener.Service1">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="wcflistener.IService1"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
和非常简单的Service1.svc.cs
[DataContract]
public class Service1 : IService1
{
public void SampleMethod(DataTable table, string name)
{
//sample method logic here
}
}
使用WCF,您可以使用几种安全选项,各有其优缺点:
这取决于您需要的身份验证级别。对于很少的客户,用户名/密码就足够了。(始终有失去这些风险)
对于主要客户2 SSL非常安全,因为人们不会轻易丢失私钥。
根据您的选择,可以共享其他代码示例。
对于选项#,请单击此链接。(您可以在以下步骤中使用SSL证书)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句