2017-03-26 21 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文件令人惊讶的.....和上述选项不帮助.....寻找专家的想法.... 修复:???探索...... 欢迎阅读此文的人士给予解答/建议。
相关问题