2017-06-18 91 views
1

我在我的IIS中安装了自己的https证书,并在我的本地计算机中将我的EchoService从http更改为https。HTTPS合同不匹配问题WCF

但是我选择运输安保后出现错误。

由于EndpointDispatcher中的ContractFilter不匹配,无法在接收方处理带Action的消息。这可能是因为合同不匹配(发件人和收件人之间的操作不匹配)或发件人和收件人之间的绑定/安全性不匹配。检查发送方和接收方是否有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无)。

客户端应用程序配置:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> 
    </startup> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="EchoService"> 
      <security mode="Transport"> 
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""></transport> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="https://desktop-rfd4j23/WCFASPNETSecurityEx/EchoService.svc" binding="wsHttpBinding" 
       bindingConfiguration="EchoService" contract="EchoService.IEchoService" name="EchoService"> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
</configuration> 

服务Web配置:

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=169433 
    --> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.6.2"/> 
    <httpRuntime targetFramework="4.6.2"/> 
    <httpModules> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/> 
    </httpModules> 
    </system.web> 
    <system.codedom> 
    <compilers> 
     <compiler language="c#;cs;csharp" extension=".cs" 
     type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
     warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/> 
     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" 
     type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
     warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/> 
    </compilers> 
    </system.codedom> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false"/> 
    <modules> 
     <remove name="ApplicationInsightsWebTracking"/> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" 
     preCondition="managedHandler"/> 
    </modules> 
    </system.webServer> 
    <system.serviceModel> 
    <bindings> 
     <webHttpBinding> 
     <binding name="wsHttp" hostNameComparisonMode="Exact"> 
      <security mode="Transport" /> 
     </binding> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFASPNETSecurityEx.EchoServiceBehavior"> 
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="WCFASPNETSecurityEx.EchoServiceBehavior" name="WCFASPNETSecurityEx.EchoService"> 
     <endpoint binding="webHttpBinding" bindingConfiguration="wsHttp" 
        name="EchoService" contract="WCFASPNETSecurityEx.IEchoService"> 
     </endpoint> 
     </service> 
    </services> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
     multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
</configuration> 

客户端代码:

Console.WriteLine("Press Enter when the web server is started"); 
Console.ReadLine(); 

EchoServiceClient client = new EchoServiceClient(); 
String result = client.Echo("Hello WCF"); 
Console.WriteLine(result); 
Console.ReadLine(); 

我刚开g调用client.Echo(“Hello WCF”)时出错。请帮我解决这个问题。谢谢。

+0

您确定您使用https访问且证书未颁发给本地主机。 –

回答

0

我应该提到wsHttpBinding而不是webHttpBinding。

<bindings> 
     <wsHttpBinding> 
     <binding name="wsHttp" hostNameComparisonMode="Exact"> 
      <security mode="Transport" > 
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""></transport> 
      <message clientCredentialType="UserName"></message> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
0

您与您的https运输锁定下来,需要用户名认证。 不应在安全模式设置为:

<security mode="TransportWithMessageCredential" > 

你处理的是在客户端的任何地方?

<serviceCredentials> 
    <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="xxx.MyUserNameValidator,xxx.WCF.Security"/> 
</serviceCredentials>