在Winform应用程序中使用SSL证书消费WCF
问题描述:
我在IIS 6.0中托管了一个.svc WCF。我在一个winform应用程序中添加了对该web服务的引用。但是,当我调用我的服务的任何方法时,我得到一个System.Net.WebException:请求失败,HTTP状态403:禁止。在Winform应用程序中使用SSL证书消费WCF
我在我的人格商店中安装了证书。
这里是我的服务器配置:
<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>
我必须修改我的winform app.config文件?我是否必须写一些代码来告诉证书在哪里?
答
问题是您的传输安全性需要SSL/Https。但你的地址是http。
更改您的地址为https
从您发布的代码:
<client>
<endpoint address="http://teclpo02.srr.fr:1098/AwsService/" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAwsService" contract="wsAws.IAwsService" name="BasicHttpBinding_IAwsService"/>
</client>
<services>
您还spesifying那个帖子可以被阻止的端口号。
客户端部分用于在我的wcf中调用另一个Web服务。通过输入HTTPS://myserver/Service.svc?wsdl,我可以在浏览器中阅读我的受保护的wcf的wsdl。所以在这种情况下,我认为这不是问题。 –