2017-03-26 34 views
-1

我創建了一個將由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自簽名證書已安裝並可用於我的系統。由於是開發,服務和客戶端都在同一系統中運行,因爲它正在開發中

我懷疑我有一個配置問題....但我的經驗較少,我找不出來。

+0

我們收到下面的答案(應該是一條評論),其內容是:「您是否使用HTTPS將綁定添加到IIS中的站點?」。這聽起來像是一個很好的問題,所以請在評論中回答 - 答案將在適當的時候刪除。 – halfer

+0

您是否使用HTTPS將綁定添加到IIS中的站點? – Parag

+0

是將綁定添加到IIS以支持https。我的問題是與我在做代碼明智的綁定有關。包括下面的答案 –

回答

0

實際上這是在服務實例化過程中引起問題的附加綁定。根據下面的評論,在instantiation部分中排序。

url = "https://localhost:550/TestService/TestService.svc"; 
       customBinding = new CustomBinding(); 
       //customBinding.Elements.Add(new ReliableSessionBindingElement()); 
       customBinding.Elements.Add(new HttpsTransportBindingElement()); 

這幫助我繼續開發整個服務和客戶端。 因此,我的解決上述問題的結論。

因爲我是wcf服務的新手,所以我遇到並解決了以下問題。有人誰是掙扎像我可以使用下面的步驟,如果你正面臨着我的錯誤

  1. 下我的服務有問題,訪問文件夾 修復:添加單獨的應用程序池有足夠權限的服務或管理員帳戶。

  2. 將wcf會話添加到現有的代碼。 修復:這是我面臨的問題,因爲我使用wshttpbinding與傳輸安全。然後,瀏覽了幾個材料和代碼後,我明白我必須使我的配置與可靠的會話和httpstransport進行自定義綁定,以進一步開發。所以我的配置大致表現爲

    <customBinding abc of wcf> 
        <reliableSession/> 
        <httpsTransport/> 
    <\customBinding> 
    

而且也未註釋以上服務實例的行了解其真正purpose.No需要可靠的會話標籤的值,並且httpsTransport安全的基本支持後。

這解決了我的第二個問題。

  1. 但是我正面臨wcf客戶端測試工具中的wsdl導入錯誤,現在我正在努力解決這個問題。 svcutil代理生成選項或添加帶uncheked彙編選項的服務引用似乎沒有工作。我還注意到,即使添加我的服務refrence新鮮客戶端沒有配置生成到我的app.config文件令人驚訝的.....和上述選項不幫助.....尋找專家的想法.... 修復:???探索...... 歡迎閱讀此文的人士給予解答/建議。
相關問題