我創建了一個將由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。我的問題是與我在做代碼明智的綁定有關。包括下面的答案 –