开发者

problem with addressfilter in WCF

开发者 https://www.devze.com 2022-12-25 20:33 出处:网络
I\'ve build my own WCF channel with all necessary stuff (like encoders, bindings, etc) to use it with ServiceHost.

I've build my own WCF channel with all necessary stuff (like encoders, bindings, etc) to use it with ServiceHost.

I just want to build the "channel stack" making no custumizations at "Service Model". To acomplish this, my encoder returns perfect ServiceModel.Messages with a XML infoset just like other channel does.

Lets assume the following service implementation:

[ServiceContract(Namespace = "http://MyNS")]  
    public interface IService1
{
    [OperationContract(IsOneWay = true)]
    void dummy()开发者_高级运维;
}

public class Service1 : IService1
{
    public void dummy()
    {
        Console.WriteLine("In Service1:dummy()");
    }
}

I used this service through other bindings and traced the following ServiceModel.Message contents (SOAP format):

    <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
        <s:Header>
               <a:Action s:mustUnderstand="1">http://MyNS/IService1/dummy</a:Action>
               <a:To s:mustUnderstand="1">amqp://localhost</a:To>
        </s:Header>
        <s:Body>
              <dummy xmlns="http://MyNS"></dummy>
        </s:Body>
    </s:Envelope>

Then (just to debug) i changed my encoder to allways return this message. When i use my custom channel the WCF's runtime replay with an faul message telling:

"The message with To '' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree."

I read that the default EndPointDispatcher.AddressFilter simply looks to the "TO" header and delivery the message to corresponding service. This is happening with other bindings, why not happens with my custom channel too?

Is there any way to i check what default AddressFilter is doing?

Thanks


This problem is how i was creating the message:

SimpleMessageBody body = new SimpleMessageBody("<dummy xmlns=\"http://MyNS\"></dummy>");

Message message = Message.CreateMessage(MessageVersion.Default, "http://MyNS/IService1/dummy", body);
MessageHeader toHeader = MessageHeader.CreateHeader("a:To", "", "amqp://localhost/", true); // DON'T DO THIS!!!
message.Headers.Add(toHeader);  

The "Action" and "To" are special headers that wcf stores in specific Message class fields. The "To" header must be specified like this:

message.Headers.To = new Uri("amqp://localhost/");

A hard to detect bug because when we look to message.ToString() we see everything in the right place...

0

精彩评论

暂无评论...
验证码 换一张
取 消