服务端配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="SZKWsHttpBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
<message clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SZKBehavior">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
<!--证书-->
<serviceCredentials>
<serviceCertificate storeName="My" x509FindType="FindBySubjectName" findValue="USER-20151214RD" storeLocation="LocalMachine"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MachineWCF.Services" behaviorConfiguration="SZKBehavior">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="SZKWsHttpBinding" contract="MachineWCF.IServices" >
</endpoint>
<!--<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange">
</endpoint>-->
<host>
<baseAddresses>
<add baseAddress="https://USER-20151214RD:9123/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
客户端添加服务端引用并运行:
异常:使用客户端身份验证方案“Anonymous”禁止HTTP请求
Server stack trace:
在 System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory`1 factory)
在 System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
在 System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
在 System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
在 System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
在 X._509.ServiceReference1.IServices.VerifyUser(String UserAccount, String UserPassWord)
在 X._509.ServiceReference1.ServicesClient.VerifyUser(String UserAccount, String UserPassWord) 位置 C:\Users\Administrator.USER-20151214RD\Desktop\X.509 客户端\X.509\Service References\ServiceReference1\Reference.cs:行号 50
在 X._509.Program.Main(String[] args) 位置 C:\Users\Administrator.USER-20151214RD\Desktop\X.509 客户端\X.509\Program.cs:行号 15