【发布时间】: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>
这没有任何运气。
【问题讨论】: