【问题标题】:AddressFilter mismatch at the EndpointDispatcher - the msg with ToEndpointDispatcher 处的 AddressFilter 不匹配 - 带有 To 的 msg
【发布时间】:2012-03-06 19:33:05
【问题描述】:

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

由于 EndpointDispatcher 的 AddressFilter 不匹配,接收方无法处理带有“http://MySite.svc/GetStateXML”的消息。检查发送方和接收方的 EndpointAddresses 是否一致

谢谢

【问题讨论】:

  • 你能告诉我们服务配置文件吗?

标签: wcf


【解决方案1】:

我在阅读 Bustamante 的 Learning WCF 书中的一个示例时也遇到了这个问题。 我使用 WCF 配置编辑器在我的主机上填写我的配置,并将值放在我的端点的 name 属性中,而不是 address 属性中。一旦我修好它,一切就奏效了。 我发现另一个帖子建议使用:

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)] 

在实现类上,它起作用但不是根本原因。

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

【讨论】:

  • 对于 VB.NET,代码是: 我不得不说这对我来说效果很好,因为外部调用方没有提供 SOAP 消息中的元素。
【解决方案2】:

下面列出的错误表明 Web Service 实现了 WS-Addressing。

“由于 EndpointDispatcher 的 AddressFilter 不匹配,接收方无法处理带有 To '' 的消息。请检查发送方和接收方的 EndpointAddresses 是否一致”

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

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

【讨论】:

  • 这个答案拯救了我的一天!此外,这个答案非常有帮助:stackoverflow.com/a/15056211/1795351
  • 这应该被标记为正确答案。完美运行。
  • 一个具体而直接的答案,立即解决了我的问题!在此实际错误消息的上下文中,我不知道如何理解这些答案的一半。这足够简洁,即使它不起作用,我也不会浪费太多时间。干得好!
【解决方案3】:

我在使用webHttpBinding 时收到此错误。

我通过添加解决了它

<endpointBehaviors>
  <behavior name="EndPointBehavior">
    <enableWebScript/>
  </behavior>
</endpointBehaviors>

&lt;behaviors&gt; 下并在我的endpoint 中设置behaviorConfiguration="EndPointBehavior"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>

【讨论】:

【解决方案4】:

我知道这听起来很傻,但对于其他有此错误的人,请检查您的地址。我们收到这个错误是因为我们有一个双斜杠,而应该只有一个。

http://localhost//servicename.svc

上面的地址导致了问题。

http://localhost/servicename.svc

没有表现出问题。

我们从 Windows 窗体和数据库中读取的部分数据动态创建完整地址。用户输入的是 /servicename.svc 而不是 servicename.svc

【讨论】:

  • 感谢您分享您的解决方案。我有一个类似的错误。我的应用程序正在引用一个引用 Web 服务的库。我有一个 Web 服务的驼峰式名称,但 Web 服务部署在 IIS 中,带有下划线,而不是驼峰式名称。将库中的名称更改为下划线版本解决了它。这就是为什么与资源的命名保持一致很重要。
  • 我知道这听起来很傻,但我也有同样的问题! :)
【解决方案5】:

我在 IIS 中托管的 Web 服务的开发环境中遇到了这个问题。通过转到“IIS 管理器”并添加绑定到错误消息中抱怨的主机名来解决此问题。

【讨论】:

    【解决方案6】:

    webHttp 属性添加到您的配置中:

    endpointBehaviors
            behavior name ="yourServiceContract"
              webHttp  automaticFormatSelectionEnabled ="true "
            behavior
    

    【讨论】:

      【解决方案7】:

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

      • 我用的是visual studio 2017
      • 我需要使用 .net 3.5 在旧应用程序上创建 wcf 服务
      • 它应该作为soap服务和“Rest”服务公开

      我需要使用的配置(其余部分)是:

      服务行为端点行为

      有一个配置
            <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>
      

      【讨论】:

        【解决方案8】:

        就我而言,我有 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 服务主机 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>
        

        【讨论】:

          【解决方案9】:

          如果您的 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>
          

          您需要像在配置文件中一样设置 EndpointAddress。 然后你需要 ClientViaBehavior 作为 baseAddress。

          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 核心,您需要自己编写 Behavior:

          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)
            {
            }
          }
          

          【讨论】:

            【解决方案10】:

            我也遇到过类似的问题。

            以下地址已提供给客户:

            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>
            

            【讨论】:

              【解决方案11】:

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

              【讨论】:

                【解决方案12】:

                &lt;webHttp /&gt;

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

                【讨论】:

                • 它是模糊的,但是通过使用这种格式(特别是两个端点)可以解决问题。确保名称都与您定义的服务相匹配。我更改了服务名称,删除了服务行为配置,并更改了第一个端点合同。
                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2013-01-02
                • 1970-01-01
                • 2013-03-09
                • 2011-03-28
                相关资源
                最近更新 更多