我需要使用通过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,还是其他什么?
提前致谢
这里没有足够的信息来确定为什么您在对服务器一无所知的情况下看到错误,但由于错误文本显示"内部错误(来自服务器)",我的猜测是它与您在客户端所做的任何事情无关。无论如何,一旦你看到这样的东西,你可能应该联系 Web 服务的所有者寻求帮助 - 如果这是一个"内部错误",他们应该负责调试它或告诉你这个"内部错误"代表你这边的实际错误。