任何想法我如何纠正这个...通过js调用服务
由于EndpointDispatcher上的AddressFilter不匹配,因此无法在接收方处理带有“http://MySite.svc/GetStateXML”的消息。检查发送方和接收方的EndpointAddresses是否一致
谢谢
看看<webHttp />
<services>
<service name="SimpleService.SimpleService" behaviorConfiguration="serviceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="SimpleService.ISimpleService" behaviorConfiguration="web">
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange">
</endpoint>
</service>
</services>
....
....
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
如果您的WCF Service.config中有多个端点,例如:
<endpoint address="urn:Service.Test" .../>
<endpoint address="urn:Service.Test2".../>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:1234/Service/" />
<add baseAddress="http://localhost:1233/Service/" />
<add baseAddress="net.pipe://localhost/Service/" />
</baseAddresses>
</host>
您需要在配置文件中设置EndpointAddress。然后,您需要baseAddress的ClientViaBehavior。
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
EndpointAddress address = new EndpointAddress("urn:Service.Test");
AndonClient client = new AndonClient(binding, address);
client.ChannelFactory.Endpoint.EndpointBehaviors.Add(new ClientViaBehavior(new Uri("net.tcp://localhost:1234/Service/Test")));
var response = client.GetDataAsync().Result;
对于.net核心,您需要自己编写行为:
public class ClientViaBehavior : IEndpointBehavior
{
Uri uri;
public ClientViaBehavior(Uri uri)
{
if (uri == null)
throw new ArgumentNullException(nameof(uri));
this.uri = uri;
}
public Uri Uri
{
get { return this.uri; }
set
{
if (value == null)
throw new ArgumentNullException(nameof(value));
this.uri = value;
}
}
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
if (clientRuntime == null)
{
throw new ArgumentNullException(nameof(clientRuntime));
}
clientRuntime.Via = this.Uri;
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
throw new NotImplementedException();
}
void IEndpointBehavior.Validate(ServiceEndpoint serviceEndpoint)
{
}
}
关键元素是webHttp和binding =“webHttpBinding”,用于浏览器测试中的Json工作。但是,SoapUI仍未能返回JSon。
我在Bustamante的学习WCF书中通过一个例子时也遇到了这个问题。我曾使用WCF配置编辑器在我的主机上填写我的配置,并将值放在我的端点的name属性中而不是address属性中。一旦我修好它就行了起来。我找到了另一篇建议使用的帖子:
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
在实现类上,它起作用但不是根本原因。
底线似乎是:确保您的客户端和服务器配置匹配。
下面列出的错误表明Web Service实现了WS-Addressing。
“由于EndpointDispatcher上的AddressFilter不匹配,无法在接收方处理带有To'的消息。检查发送方和接收方的EndpointAddresses是否一致”
在SOAP Headers中包含以下内容以访问Web Service:
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://example.com/service</wsa:To>
</soap:Header>
我在使用webHttpBinding
时遇到了这个错误。
我通过添加来解决它
<endpointBehaviors>
<behavior name="EndPointBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
在<behaviors>
下,用behaviorConfiguration="EndPointBehavior"
在我的endpoint
中设置binding="webHttpBinding"
。
完整配置:
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndPointBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address=""
binding="webHttpBinding"
contract="WcfService1.IService1"
behaviorConfiguration="EndPointBehavior">
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange">
</endpoint>
</service>
</services>
我知道这听起来很愚蠢,但对于有此错误的其他人,请检查您的地址。我们得到了这个错误,因为我们有一个双斜线,其中应该只有一个。
http://localhost//servicename.svc
上述地址引起了这个问题。
http://localhost/servicename.svc
没有表现出这个问题。
我们从Windows窗体和数据库中读取的数据部分动态创建完整地址。用户输入的是/servicename.svc而不是servicename.svc
我在开发环境中遇到了IIS中托管的Web服务的问题。通过转到“IIS管理器”解决了这个问题,并在错误消息中添加了对主机名称的绑定。
将webHttp
属性添加到您的配置:
endpointBehaviors
behavior name ="yourServiceContract"
webHttp automaticFormatSelectionEnabled ="true "
behavior
我有同样的问题,只是为了完成:
我需要使用的配置(对于休息部分)是:
有一个服务行为和端点行为的配置
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webEndpointBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="My.Service" behaviorConfiguration="myServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="My.IService" behaviorConfiguration="webEndpointBehaviour">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
在我的例子中,我有一个WCF服务库应用程序,它是一个RESTFul和Windows服务主机。我有Host App.Config的问题。请看下面
WCF休息服务App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="MyService.DocumentWCFRESTService" behaviorConfiguration="defaultServiceBehavior">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="http://localhost:2023/DocumentWCFRESTService"
binding="webHttpBinding" behaviorConfiguration="webBehaviorConfiguration"
contract="MyService.IDocumentWCFRESTService" >
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<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"/>
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/Document.Server.WCFREST.Service/DocumentWCFRESTService/" />
</baseAddresses>
</host>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings> </bindings>
<behaviors>
<serviceBehaviors>
<behavior name="defaultServiceBehavior">
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:2023/DocumentWCFRESTService"/>
<!-- 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="False" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehaviorConfiguration">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Windows服务主机App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingConfiguration" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="documentWCFRESTServiceBehavior">
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:2023/DocumentWCFRESTService"/>
<!-- 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="False" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehaviorConfiguration">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyService.DocumentWCFRESTService" behaviorConfiguration="documentWCFRESTServiceBehavior">
<endpoint address="http://localhost:2023/DocumentWCFRESTService" behaviorConfiguration="webBehaviorConfiguration"
binding="webHttpBinding" bindingConfiguration="webHttpBindingConfiguration"
contract="MyService.IDocumentWCFRESTService"></endpoint>
</service>
</services>
</system.serviceModel>
</configuration>