我创建了一个将由Windows客户端使用并使用的HTTP wcf服务。在我使用HTTP之前,我没有任何问题。现在我的客户想要将该网站更改为HTTPS。所以为了开发目的,我使用了IIS Express证书并设置了服务。现在我的服务已经启动并运行在iisexpress自签名证书的IIS中。我可以通过浏览器以及wcf测试客户端工具浏览我的新的https服务。WCF服务在从http更改为https之后从客户端调用方法时返回错误“EndFileDispatcher中的ContractFilter不匹配”
但是当我尝试从我的Windows应用程序调用方法到新的https wcf服务。创建我的服务实例,但只能调用一个方法过程中出现了以下错误:
System.ServiceModel.ActionNotSupportedException was unhandled by user code HResult=-2146233087 Message=The message with Action ' http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence ' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
在服务我绑定配置(配置3时在HTTPS在HTTP模式使用模式和配置2使用)如如下:
<bindings>
<wsHttpBinding>
<binding name="wsHttpBinding_IPGPService">
<!--config test 1 - start -->
<!--<security mode="None">
<transport clientCredentialType="None" />
<message establishSecurityContext="false" />
</security>-->
<!--config test 1 - end -->
<!--config test 2 - start -->
<!--<security mode="None" />
<reliableSession enabled="true" />-->
<!--config test 2 - end -->
<!--config test 3 - start -->
<!--<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"/>
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>-->
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
<!--config test 3 - end -->
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="PGPService.PGPService">
<endpoint address="" binding="wsHttpBinding" contract="PGPService.IPGPService" bindingConfiguration="wsHttpBinding_IPGPService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<!--<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<!--<serviceDebug includeExceptionDetailInFaults="false"/>-->
<!--test config - start-->
<serviceDebug includeExceptionDetailInFaults="True" />
<!--test config - end-->
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
在客户端我们使用自定义绑定创建服务实例。
url = "https://localhost:550/TestService/TestService.svc";
customBinding = new CustomBinding();
customBinding.Elements.Add(new ReliableSessionBindingElement());
customBinding.Elements.Add(new HttpsTransportBindingElement());
EndpointAddress endpointAdress = new EndpointAddress(url);
pgpServiceClientInstance = new PGPServiceClient(customBinding, endpointAdress);
pgpServiceClientInstance.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.CurrentUser,
StoreName.Root,
X509FindType.FindByThumbprint,
"03815c894b62dcf2d17336ade2d9ca61ddb7f92c");
加入服务后引用在我的Windows应用程序生成的的app.config如下:
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPGPService">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:550/TestService/TestService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IPGPService"
contract="PGPServiceReference.IPGPService" name="WSHttpBinding_IPGPService" />
</client>
所以,现在我可以看到我的服务实例是越来越创建成功。但在调用方法的时候,我得到了上面的错误。
在服务端转移到https之前和之后没有更改代码。这是相同的服务代码。它在http上完全正常工作,但在https上被破坏。
我完全删除了服务引用,并在使我的wcf服务https后新添加它。 IIS express自签名证书已安装并可用于我的系统。由于是开发,服务和客户端都在同一系统中运行,因为它正在开发中
我怀疑我有一个配置问题....但我的经验较少,我找不出来。
我们收到下面的答案(应该是一条评论),其内容是:“您是否使用HTTPS将绑定添加到IIS中的站点?”。这听起来像是一个很好的问题,所以请在评论中回答 - 答案将在适当的时候删除。 – halfer
您是否使用HTTPS将绑定添加到IIS中的站点? – Parag
是将绑定添加到IIS以支持https。我的问题是与我在做代码明智的绑定有关。包括下面的答案 –