端点调度程序上的地址过滤器不匹配 - 带有 To 的消息



任何想法我如何纠正这一点.. 通过 js 调用服务

带有 To "http://MySite.svc/GetStateXML" 的消息无法在接收方处理,因为端点调度程序的地址过滤器不匹配。 检查发送方和接收方的端点地址是否一致

谢谢

下面

列出的错误指示 Web 服务实现了 WS 寻址。

"由于端点调度程序的地址过滤器不匹配,收件人无法处理带有 To '' 的消息。 检查发送方和接收方的端点地址是否一致">

在 SOAP 标头中包含以下内容以访问 Web 服务:

<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>http://example.com/service</wsa:To>
</soap:Header>

我在浏览 Bustamante 的学习 WCF 书中的一个例子时也遇到了这个问题。我使用 WCF 配置编辑器在主机上填写了配置,并将值放在终结点的 name 属性中,而不是地址属性中。 一旦我修复了它,事情就工作了。我发现了另一个建议使用以下内容的帖子:

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] 

在实现类上,它有效但不是根本原因。

底线似乎是:确保您的客户端和服务器配置匹配。

我在使用 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

我遇到了同样的问题,只是为了完整:

  • 我使用了Visual Studio 2017
  • 我需要使用 .net 3.5 在旧应用程序上创建一个 wcf 服务
  • 它应该作为肥皂服务和"休息"服务公开

我需要使用的配置(用于休息部分(是:

有一个服务行为和端点行为的配置

      <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 Rest Service 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 Service Host 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>

如果 WCFService.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>

您需要像在配置文件中一样设置端点地址。然后,您需要 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)
  {
  }
}

我也有类似的问题。

向客户提供以下地址:

https://test.mycompany.ru/ChannelService/api/connect.svc

但根据日志,客户端向以下地址发送了请求:

https://test.mycompany.ru/ChannelService/api/connect.svc/SOAP/Adapter

将终结点地址添加到配置文件后,服务开始工作:

 <services>
      <service name="connect">
        <endpoint address="/SOAP/Adapter"
                  binding="basicHttpBinding"
                  bindingConfiguration="secureHttpBinding"
                  contract="IContract">   
        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpsBinding"
                  contract="IMetadataExchange"/>
      </service>
    </services>

关键元素是 webHttp 和 binding="webHttpBinding" 用于浏览器测试中的 Json 工作。但是 SoapUI 仍然无法返回 JSon。

看看<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>

相关内容

最新更新