将标头添加到EndpointAddress

时间:2013-11-04 07:43:54

标签: c#

有没有办法向EndpointAddress添加标头?

我试过了:

    public static ChannelFactory<IClass> CreateFactory()
    {
        var authorization = new Authorization()
        {
            Key = "test"
        };
        AddressHeader header = AddressHeader.CreateAddressHeader(authorization);

        var address = new EndpointAddress(ClientConfig.Endpoint, header);
        var channel = new ChannelFactory<IClass>(address.ResolveBinding(), address);
        return channel;
    }

出于某种原因,new EndpointAddress无效,因为它无法理解标题

  

('System.ServiceModel.EndpointAddress.EndpointAddress(System.Uri,System.ServiceModel.EndpointAddress)'的最佳重载方法匹配'有一些无效的参数。)

没有标题,一切都还可以。

我做错了什么?我不明白......

1 个答案:

答案 0 :(得分:2)

通过查看official documentation of EndpointAddress,您可以看到此类不会在其构造函数中接受单个EndpointAddress,而是接受EndpointAdress对象的数组。

所以你应该尝试:

AddressHeader header = AddressHeader.CreateAddressHeader(authorization);
var address = new EndpointAddress(ClientConfig.Endpoint, new[] { header });