【问题标题】:HTTPS Contract Mismatch issue WCFHTTPS 合同不匹配问题 WCF
【发布时间】:2017-06-18 18:14:55
【问题描述】:

我在我的 IIS 中安装了自己的 https 证书,并在我的本地机器上将我的 EchoService 从 http 更改为 https。

但在选择传输安全性后,我遇到了错误。

由于 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>

服务网络配置:

<?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();

调用 client.Echo("Hello WCF"); 时出错请帮我解决这个问题。谢谢。

【问题讨论】:

  • 您确定您使用 https 访问并且证书未颁发给 localhost。

标签: asp.net-mvc wcf security iis wcf-security


【解决方案1】:

我应该提到 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>

【讨论】:

    【解决方案2】:

    您正在使用 https 锁定您的传输并要求用户名身份验证。 安全模式不应该设置为:

    <security mode="TransportWithMessageCredential" >
    

    您是否在任何地方的客户中处理该问题?

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

    【讨论】:

      猜你喜欢
      • 2010-11-18
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多