首页 新闻 会员 周边

WCF 中使用X509证书后调用失败

0
悬赏园豆:50 [已解决问题] 解决于 2013-01-11 10:54

通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态。

//服务端配置
<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfSafeTest.Services.PaymentService">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="None" />
            </clientCertificate>
            <serviceCertificate findValue="tech-server" storeLocation="LocalMachine"
              storeName="My" x509FindType="FindBySubjectName" />
          </serviceCredentials>
        </behavior>


        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>
      <service name="WcfSafeTest.Services.PaymentService" behaviorConfiguration="WcfSafeTest.Services.PaymentService">
        <endpoint address="" contract="WcfSafeTest.Services.IPaymentService"    binding="wsHttpBinding"   bindingConfiguration="myUserSafeBinding">
          <identity>
            <dns value="tech-server"></dns>
          </identity>
        </endpoint>
      </service>
    </services>

    <bindings>
      <wsHttpBinding >
        <binding name="myUserSafeBinding">
          <security mode="Message">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""></transport>
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>


    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

//客服端配置:
<system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IPaymentService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="Message">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""></transport>
            <message clientCredentialType="Certificate" negotiateServiceCredential="true"
              algorithmSuite="Default" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://192.168.0.2:10009/Services/PaymentService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPaymentService"
        contract="PaymentServiceReference.IPaymentService" name="WSHttpBinding_IPaymentService">
        <identity>
          <dns value="tech-server" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
//证书名称就是tech-server
David·Li的主页 David·Li | 初学一级 | 园豆:76
提问于:2013-01-10 11:06
< >
分享
最佳答案
0

事实上,这个问题得原因是因为服务端与客服端配置不一致引起的,添加x509证书认证之后,需要在客服端手动添加服务行为配置,这个过程网上案例很多,主要是要仔细分析。

David·Li | 初学一级 |园豆:76 | 2013-01-11 10:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册