简体   繁体   English

在Winform应用程序中使用由SSL证书保护的WCF

[英]Consume WCF secured with SSL certificate in a winform application

I hosted a .svc WCF in IIS 6.0. 我在IIS 6.0中托管了.svc WCF。 I added a reference to that web service in a winform application. 我在winform应用程序中添加了对该Web服务的引用。 However, when I call any method of my service I get a System.Net.WebException: The request failed with HTTP status 403: Forbidden. 但是,当我调用服务的任何方法时,都会得到System.Net.WebException:请求失败,HTTP状态为403:禁止。

I have the certificate installed in my personnal store. 我的个人商店中已安装证书。

Here's my server config: 这是我的服务器配置:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IAwsService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="UserName" algorithmSuite="Default"/>
      </security>
    </binding>
  </basicHttpBinding>
  <wsHttpBinding>
    <binding name="TransportSecurity">
      <security mode="Transport">
        <transport clientCredentialType="Certificate"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://teclpo02.srr.fr:1098/AwsService/" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAwsService" contract="wsAws.IAwsService" name="BasicHttpBinding_IAwsService"/>
</client>
<services>
  <service name="AuthWorkStation_Wcf_Web.AwsService" behaviorConfiguration="ServiceBehavior">
    <endpoint name="" address="" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="AuthWorkStation_Wcf_Web.IAwsService" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceCredentials>
        <clientCertificate>
          <authentication certificateValidationMode="None" revocationMode="NoCheck" />
        </clientCertificate>
        <serviceCertificate storeName="Root" findValue="CA_SRR_DISTRIB" x509FindType="FindBySubjectName" />
      </serviceCredentials>
      <serviceMetadata httpsGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

Do I have to edit my winform app.config file ? 我是否需要编辑winform app.config文件? Do I have to write some line of code to tell where is the certificate ? 我是否需要编写一些代码行来告诉证书在哪里?

The problem is that you have transport security which requires SSL/Https. 问题是您具有需要SSL / Https的传输安全性。 But your address is http. 但是您的地址是http。

Change your address to https 将您的地址更改为https

From the code you posted: 从您发布的代码中:

 <client> 
   <endpoint address="http://teclpo02.srr.fr:1098/AwsService/" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAwsService" contract="wsAws.IAwsService" name="BasicHttpBinding_IAwsService"/> 
 </client> 
<services> 

You are also spesifying the port number that post could be blocked. 您还在美化可能阻止发布的端口号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM