我为客户端创建了一个WCF服务,以便与ASP.NET应用程序通信。该服务是在客户端上创建的,ASP.NET应用程序可以调用该服务。现在我在沟通时没有使用安全措施。
到目前为止,服务已创建并正在运行。 ASP.NET应用程序为它创建了一个ServiceReference,但在尝试调用方法时,我收到以下错误消息(调试开启):
带有Action' http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue'的消息由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理。这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配。检查发件人和收件人是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无)。
足够简单,app.config问题。我似乎无法找出问题是什么,因为我已经将app.config从WCF主机复制到了ASP。应用
客户端的App.config(WCF主机):
<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>
这没有运气。
答案 0 :(得分:0)
我认为您需要在客户端配置中配置绑定安全性的所有属性,以匹配服务器发送的内容。
<security>
<transport/>
<message/>
</security>
答案 1 :(得分:0)
我的问题是我在端点下面缺少端点地址(http://local.host:8732/WCF/)。那令人尴尬。
感谢。