通过https使用WCF服务

时间:2012-12-17 13:02:21

标签: wcf authentication https ssl-certificate x509certificate

我需要使用通过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>

我的问题是,这个错误是关于客户端身份验证throw ssl,还是其他什么?

提前致谢

1 个答案:

答案 0 :(得分:0)

这里没有足够的信息来确定你在不知道服务器的情况下看到错误的原因,但由于错误文本显示“内部错误(来自服务器)”,我的猜测是它与它无关你在客户端做的任何事情。在任何情况下,一旦你看到这样的东西,你应该联系网络服务的所有者寻求帮助 - 如果这是一个“内部错误”,他们应该负责调试它或告诉你你的实际错误是什么这个“内部错误”代表。