我使用这个 web.config 创建了一个简单的 wcf 服务以部署在 iis 上:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Verbose"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "log.e2e" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="WcfService1.Service1">
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="wsHttpEndpointBinding"
name="wsHttpEndpoint" contract="WcfService1.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration=""
name="MexHttpsBindingEndpoint" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Windows" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
我在关注这个例子:
http://msdn.microsoft.com/en-us/library/aa354508%28v=vs.100%29.aspx
会员身份认证除外。我按照程序在我的客户端机器和服务器机器上安装了证书。如果我浏览该服务,则会显示证书问题,但无论如何我可以访问不推荐的站点并且可以看到 wsdl。使用 wcf 客户端时,它会引发错误“无法为 SSL/TLS 安全通道建立信任关系”。但是使用 WCFStorm www.wcfstorm.com/,它可以工作。
我不知道是否总是需要验证来自客户端的证书,或者证书是否有问题。这是一个测试环境...感谢任何指导!