【问题标题】:WCF service, two-way communication - message security noneWCF 服务,双向通信 - 消息安全无
【发布时间】:2014-06-24 15:31:31
【问题描述】:

我为客户端创建了一个 WCF 服务以与 ASP.NET 应用程序进行通信。该服务是在客户端上创建的,ASP.NET 应用程序可以调用该服务。目前我在交流时没有使用任何安全措施。

到目前为止,服务已创建并正在运行。 ASP.NET 应用程序已为其创建了一个 ServiceReference,但在尝试调用一个方法时,我收到以下错误消息(正在调试):

由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有 Action 'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue' 的消息。这可能是因为合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。

很简单,app.config 的问题。我似乎无法找出问题所在,因为我已将 app.config 从 WCF 主机复制到 ASP。申请。

客户端(WCF 主机)的 App.config:

<system.serviceModel>
<bindings>
<wsHttpBinding>
  <binding name="WSHttpBinding_Interface" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="00:01:00" 
           bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
           messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <reliableSession ordered="true" inactivityTimeout="infinite" enabled="false" />
      <security mode="None">
      </security>
  </binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/WCF/" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Interface" contract="WCFProject.IInterface" name="WSHttpBinding_Interface">
  <identity>
    <dns value="localhost" />
  </identity>
</endpoint>
</client>
<services>
<service name="WCFProject.Interface" behaviorConfiguration="WCFProject.InterfaceBehavior">
  <endpoint address="" binding="wsHttpBinding" contract="WCFProject.IInterface" bindingConfiguration="WSHttpBinding_Interface" name="WCFProject.Interface.EndpointConfiguration">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
  <!-- Metadata Endpoints -->
  <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
  <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
  <behavior name="WCFProject.InterfaceBehavior">
    <!-- To avoid disclosing metadata information, 
      set the value below to false and remove the metadata endpoint above before deployment -->
    <serviceMetadata httpGetEnabled="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="True" />
  </behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

ASP 应用程序的 App.config(ServiceReference 名为 InterfaceService):

<system.serviceModel>
<bindings>
<wsHttpBinding>
  <binding name="WSHttpBinding_Interface" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="00:01:00" 
           bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 
           messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <reliableSession ordered="true" inactivityTimeout="infinite" enabled="false" />
      <security mode="None">
      </security>
  </binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/WCF/" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Interface" contract="InterfaceService.IInterface" name="WSHttpBinding_Interface">
  <identity>
    <dns value="localhost" />
  </identity>
</endpoint>
</client>
</system.serviceModel>

在 ASP 应用程序中启动 WCF 服务如下,其中 WCFrl 是 WCF 服务的 url:

            //Create object of the Binding
        System.ServiceModel.Channels.Binding binding = new System.ServiceModel.WSHttpBinding();
        //Create endpointAddress of the Service
        System.ServiceModel.EndpointAddress endpointAddress = new
        System.ServiceModel.EndpointAddress(WCFUrl + "?wsdl");
        //Create Client of the Service
        InterfaceService.InterfaceClient cc = new InterfaceService.InterfaceClient(binding, endpointAddress);
        //Call Service method using ServiceClient
        string ss = cc.Ping();

任何为我指明正确方向的帮助都会受到重视。我已经坚持了几天了。 谢谢。

更新: 我还在两边添加了以下内容:

       <security mode="None">
        <transport clientCredentialType="None"/>
        <message establishSecurityContext="false"/>
      </security>

这没有任何运气。

【问题讨论】:

    标签: c# asp.net wcf


    【解决方案1】:

    我认为您需要在客户端配置中配置绑定安全的所有属性以匹配服务器发送的内容。

    <security>
        <transport/>
        <message/>
     </security>
    

    【讨论】:

    • 谢谢,我发现我使用了一些旧的 app.config。我添加了相同级别的 元素,但问题仍然相同。我更新了上面的帖子。
    • 客户端访问服务的配置方式与服务与客户端通信的方式存在一些问题。这是当您使用 http 访问需要 https 的 wcf 服务时发生的错误类型。最好的做法是从头开始使用没有安全性或配额的普通 http 绑定,然后一次构建一个。在旁注中,我在 Visual Studio 中调试时遇到了这个错误。当我部署到 IIS 时,一切正常。只是VS不喜欢用https访问asp.net开发服务器。
    【解决方案2】:

    我的问题是我在端点下缺少端点地址 (http://local.host:8732/WCF/)。好尴尬。

    谢谢。

    【讨论】:

      猜你喜欢
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 2014-06-19
      • 1970-01-01
      • 2012-03-13
      相关资源
      最近更新 更多