AddressFilter mismatch at the EndpointDispatcher - the msg with To

前端 未结 12 1836
一个人的身影
一个人的身影 2020-12-14 06:21

Any ideas how I correct this.. calling a service via js

The message with To \'http://MySite.svc/GetStateXML\' cannot be processed at the receiver, due

12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 06:40

    if you have multiple endpoints in your WCFService.config like:

    
    
    
      
        
        
        
      
    
    

    You need to set EndpointAddress like in your config file. Then you need ClientViaBehavior for the 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;
    

    For .net core you need to write the Behavior by yourself:

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

提交回复
热议问题