C# 客户端如何获得服务安全SSL?
我有一个服务班:C# 客户端如何获得服务安全SSL?,c#,wcf,web-services,C#,Wcf,Web Services,我有一个服务班: namespace TestService { public class Service:IService { #region IService Members public string TestCall() { return "You just called a WCF webservice On SSL(Transport Layer Security)"; }
namespace TestService
{
public class Service:IService
{
#region IService Members
public string TestCall()
{
return "You just called a WCF webservice On SSL(Transport Layer Security)";
}
#endregion
}
}
和配置服务:
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="returnFaults" name="TestService.Service">
<endpoint binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="TestService.IService"/>
<endpoint address="mex" binding="mexHttpsBinding" name="MetadataBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpsGetEnabled="true"/>
<serviceTimeouts/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<diagnostics>
<messageLogging logEntireMessage="true" maxMessagesToLog="300" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="true"/>
</diagnostics>
</system.serviceModel>
</configuration>
它返回错误:
根据验证,远程证书无效
程序
此配置客户端:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://thanguk-pc/service.svc" binding="wsHttpBinding" behaviorConfiguration="firstSsl"
bindingConfiguration="WSHttpBinding_IService" contract="ServiceReference1.IService"
name="WSHttpBinding_IService" >
<identity>
<dns value="WcfServer" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="firstSsl">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None" revocationMode="NoCheck"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
客户使用服务时有什么问题?谢谢我觉得WCF配置不错。因此,我将开始关注您的证书、证书安装和(正如@flem所指出的)。是谁颁发的证书?听起来它可能是自签名的。在测试期间,客户端上不会信任自签名证书。您可以在服务器上运行(打开TLS过滤器)并查看SSL握手。这可能会让您了解故障发生的位置
一个技巧是,为了让服务正常工作,您应该能够通过https从客户端浏览元数据(.svc),而不会出现任何浏览器证书错误(例如,chrome上的绿色锁)。如果浏览器变为绿色,则通常证书已正确安装和配置。否则,WCF也会拒绝它(但不会给您继续的选项)。这能解决您的问题吗?谢谢,弗莱姆,但我找不到解决办法,我在证书上似乎有问题。谢谢,我正在努力寻找它。我发现chrome是调试这些问题的好工具。如果你点击红色的锁,它会让你很好地了解信任链中的漏洞。
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://thanguk-pc/service.svc" binding="wsHttpBinding" behaviorConfiguration="firstSsl"
bindingConfiguration="WSHttpBinding_IService" contract="ServiceReference1.IService"
name="WSHttpBinding_IService" >
<identity>
<dns value="WcfServer" />
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="firstSsl">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None" revocationMode="NoCheck"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>