我需要使用通过 https 连接公开的 Web 服务,该服务由给我证书 (.pfx) 和密码的客户端管理,所以我需要对该服务调用一个操作但是我在尝试时遇到了一些问题它。
也许我没有正确创建客户端和服务之间的 ssl 连接,我将展示我的 web.config 和一段调用服务的代码
web.config
:
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="credentialConfiguration">
<clientCredentials>
<clientCertificate
findValue="10 14 08 f4 00 00 00 00 0f 3f"
storeLocation="CurrentUser"
x509FindType="FindBySerialNumber"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="myBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://aaaaaaaaaaaaaaaaaa:700/aaa/aa/"
behaviorConfiguration="credentialConfiguration"
binding="wsHttpBinding"
bindingConfiguration="myBinding"
contract="mydll.service"
name="faturasSOAP" />
</client>
</system.serviceModel>
</configuration>
调用服务的代码:
//Create authentication header
CdoHeaderCredentials header = GetEncryptedCredentials();
//Client Proxy
InvoiceService.faturasClient clientProxy = new faturasClient();
//Custom header
AddWseSecurityHeaderEndpointBehavior customEndpointBehavior =
new AddWseSecurityHeaderEndpointBehavior(header.Username, header.Password, header.Nonce, header.ClientDate);
clientProxy.Endpoint.Behaviors.Add(customEndpointBehavior);
//get document to register on service
RegisterInvoiceType documentToSnyc = manager.DocumentToSnyc();
//Load private certificate with key
X509Certificate2 cert = new X509Certificate2(
certPath,
_certKey,
X509KeyStorageFlags.Exportable);
//Link the certificate with the proxy
clientProxy.ClientCredentials.ClientCertificate.Certificate = cert;
//invoke operation
RegisterInvoiceResponse response = clientProxy.RegisterInvoice(new RegisterInvoiceRequest(documentToSnyc));
每当我调用服务时,响应都是相同的:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<s:Header xmlns:s="http://www.w3.org/2003/05/soap-envelope" />
<env:Body>
<env:Fault>
<env:Code>
<env:Value>
env:Receiver</env:Value>
</env:Code>
<env:Reason>
<env:Text xml:lang="en-US">
Internal Error (from server)
</env:Text>
</env:Reason>
</env:Fault>
</env:Body>
</env:Envelope>
我的问题是,如果这个错误是关于客户端身份验证抛出 ssl,还是其他什么?
提前致谢