WCF 服务 returns 从 http 更改为 https 后从客户端调用方法时出错 "ContractFilter mismatch at the EndpointDispatcher"
WCF Service returns Error when invoking method from client after changing from http to https "ContractFilter mismatch at the EndpointDispatcher"
我创建了一个 HTTP wcf 服务,该服务将由 windows 客户端使用并加以利用。在我使用 HTTP 之前,我没有遇到任何问题。现在我的客户想要将站点更改为 HTTPS。因此出于开发目的,我使用了 IIS 快速证书并设置了服务。现在我的服务已经启动并且在 IIS 中使用 iisexpress 自签名证书 运行。我能够通过浏览器以及 wcf 测试客户端工具浏览我的新 https 服务。
但是当我尝试从我的 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模式下使用,配置2在http模式下使用)如下:
<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 快速自签名证书已在我的系统上安装并可用。服务和客户端都运行在同一个系统中,因为它是开发
我怀疑我有配置问题....但由于经验不足我无法弄清楚。
实际上是服务实例化期间的附加绑定导致了问题。通过在实例化部分的下方注释对其进行排序。
url = "https://localhost:550/TestService/TestService.svc";
customBinding = new CustomBinding();
//customBinding.Elements.Add(new ReliableSessionBindingElement());
customBinding.Elements.Add(new HttpsTransportBindingElement());
这帮助我继续开发整个服务和客户端。
我对上述问题的修复到此结束。
由于我是 wcf 服务的新手,所以我面临着以下问题,这些问题我都遇到并解决了。如果你遇到我的错误,像我一样挣扎的人可以使用下面的步骤
接下来我的服务在访问文件夹时出现问题
修复:使用具有足够权限的服务或管理员帐户添加单独的应用程序池。
将 wcf 会话添加到现有代码。
修复:这是我面临问题的地方,因为我正在使用具有传输安全性的 wshttpbinding。然后在浏览了几种材料和代码后,我必须将我的配置设置为使用 reliablesession 和 httpstransport 进行自定义绑定,以便进一步进行开发。所以我的配置大致显示为
<customBinding abc of wcf>
<reliableSession/>
<httpsTransport/>
<\customBinding>
并且在了解其真正 purpose.No 需要可靠会话标记和 httpsTransport 中的任何值以实现安全性的基本支持后,在服务实例化行上方也取消注释。
这解决了我的第二个问题。
- 但是,我现在正在努力解决 wcf 客户端测试工具中的 wsdl 导入错误。 svcutil 代理生成选项或使用 uncheked 程序集选项添加服务引用似乎不起作用。我还注意到,即使将我的服务引用新鲜地添加到客户端,我的 app.config 文件也没有生成任何配置,这令人惊讶……而且上面提到的选项无济于事……寻找专家的想法…… .
使固定 : ???正在探索....
欢迎阅读本文的灵魂给予answer/suggestion.
我创建了一个 HTTP wcf 服务,该服务将由 windows 客户端使用并加以利用。在我使用 HTTP 之前,我没有遇到任何问题。现在我的客户想要将站点更改为 HTTPS。因此出于开发目的,我使用了 IIS 快速证书并设置了服务。现在我的服务已经启动并且在 IIS 中使用 iisexpress 自签名证书 运行。我能够通过浏览器以及 wcf 测试客户端工具浏览我的新 https 服务。
但是当我尝试从我的 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模式下使用,配置2在http模式下使用)如下:
<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 快速自签名证书已在我的系统上安装并可用。服务和客户端都运行在同一个系统中,因为它是开发
我怀疑我有配置问题....但由于经验不足我无法弄清楚。
实际上是服务实例化期间的附加绑定导致了问题。通过在实例化部分的下方注释对其进行排序。
url = "https://localhost:550/TestService/TestService.svc";
customBinding = new CustomBinding();
//customBinding.Elements.Add(new ReliableSessionBindingElement());
customBinding.Elements.Add(new HttpsTransportBindingElement());
这帮助我继续开发整个服务和客户端。 我对上述问题的修复到此结束。
由于我是 wcf 服务的新手,所以我面临着以下问题,这些问题我都遇到并解决了。如果你遇到我的错误,像我一样挣扎的人可以使用下面的步骤
接下来我的服务在访问文件夹时出现问题 修复:使用具有足够权限的服务或管理员帐户添加单独的应用程序池。
将 wcf 会话添加到现有代码。 修复:这是我面临问题的地方,因为我正在使用具有传输安全性的 wshttpbinding。然后在浏览了几种材料和代码后,我必须将我的配置设置为使用 reliablesession 和 httpstransport 进行自定义绑定,以便进一步进行开发。所以我的配置大致显示为
<customBinding abc of wcf> <reliableSession/> <httpsTransport/> <\customBinding>
并且在了解其真正 purpose.No 需要可靠会话标记和 httpsTransport 中的任何值以实现安全性的基本支持后,在服务实例化行上方也取消注释。
这解决了我的第二个问题。
- 但是,我现在正在努力解决 wcf 客户端测试工具中的 wsdl 导入错误。 svcutil 代理生成选项或使用 uncheked 程序集选项添加服务引用似乎不起作用。我还注意到,即使将我的服务引用新鲜地添加到客户端,我的 app.config 文件也没有生成任何配置,这令人惊讶……而且上面提到的选项无济于事……寻找专家的想法…… . 使固定 : ???正在探索.... 欢迎阅读本文的灵魂给予answer/suggestion.