1

有没有办法向 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)' 的最佳重载方法匹配有一些无效参数。)

没有标题一切正常。

我做错了什么?我无法理解...

4

1 回答 1

4

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

所以你应该尝试:

AddressHeader header = AddressHeader.CreateAddressHeader(authorization);
var address = new EndpointAddress(ClientConfig.Endpoint, new[] { header });
于 2013-11-04T08:18:10.173 回答