簡體   English   中英

WCF服務,雙向通信-消息安全無

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

我已經為客戶端創建了WCF服務以與ASP.NET應用程序進行通信。 該服務是在客戶端上創建的,ASP.NET應用程序可以調用該服務。 目前,我在交流時沒有使用任何安全性。

到目前為止,服務已創建並正在運行。 ASP.NET應用程序已經為其創建了ServiceReference,但是當嘗試調用方法時,出現以下錯誤消息(調試時):

由於EndpointDispatcher上的ContractFilter不匹配,因此無法在接收方處理帶有操作' 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>

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

向我指出正確方向的任何幫助均適用。 我已經堅持了幾天。 謝謝。

更新:我還在兩邊都添加了以下內容:

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

這沒有任何運氣。

我認為您需要在客戶端配置中配置綁定安全性的所有屬性,以匹配服務器發送的內容。

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

我的問題是我缺少端點下面的端點地址( http://local.host:8732/WCF/ )。 不好意思

謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM