简体   繁体   English

WCF服务,双向通信-消息安全无

[英]WCF service, two-way communication - message security none

I have created a WCF service for a client to communicate with an ASP.NET application. 我已经为客户端创建了WCF服务以与ASP.NET应用程序进行通信。 The service is created on the client, which the ASP.NET application can invoke. 该服务是在客户端上创建的,ASP.NET应用程序可以调用该服务。 For now I'm using no security when communicating. 目前,我在交流时没有使用任何安全性。

So far the service is created and running. 到目前为止,服务已创建并正在运行。 The ASP.NET application has created a ServiceReference to it, but when trying to invoke a method I get the following error message (debugging on): ASP.NET应用程序已经为其创建了ServiceReference,但是当尝试调用方法时,出现以下错误消息(调试时):

The message with Action ' http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue ' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. 由于EndpointDispatcher上的ContractFilter不匹配,因此无法在接收方处理带有操作' http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue '的消息。 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, eg Message, Transport, None). 检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如,消息,传输,无)。

Easy enough, issues with the app.config. 很简单,app.config出现问题。 I cannot seem to find out what's the issue, since I've copied the app.config from the WCF host to the ASP. 我似乎无法找出问题所在,因为我已将app.config从WCF主机复制到ASP。 application. 应用。

App.config for the client (WCF host): 客户端(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>

App.config for the ASP application (ServiceReference is named InterfaceService): 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>

The WCF service is initiated in the ASP application as following, where the WCFUrl is the url to the WCF service: WCF服务在ASP应用程序中按以下方式启动,其中WCFUrl是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();

Any help pointing me to the right direction is appriciated. 向我指出正确方向的任何帮助均适用。 I've been stuck on this for a few days. 我已经坚持了几天。 Thanks. 谢谢。

Update: I have also added the following in the on both sides: 更新:我还在两边都添加了以下内容:

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

This without any luck. 这没有任何运气。

I think you need to configure all attributes of the bindings security in the client configuration to match what is the server is sending out. 我认为您需要在客户端配置中配置绑定安全性的所有属性,以匹配服务器发送的内容。

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

My issue was that I'm missing the endpoint address ( http://local.host:8732/WCF/ ) underneath the endpoint. 我的问题是我缺少端点下面的端点地址( http://local.host:8732/WCF/ )。 That's embarrasing. 不好意思

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM