2013-11-04 34 views
0

是否有任何方法将标题添加到端点地址?将标题添加到端点地址

我尝试这样做:

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不bacause它的工作不能理解头

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

没有标题所有内容好的。

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

回答

2

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

所以,你应该尝试:

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

都能跟得上。问题没有改变。 EndpointAddress应该有公共的EndpointAddress(Uri URI,EndpointIdentity标识,params AddressHeader [] addressHeaders);但它根本不起作用,或者我仍然错过了一些东西。 –

+0

你是如何更改EndpointAddress的初始化的?你现在有什么异常? –

+0

仍然和我的问题一样。我尝试了你的建议,没有任何改变:( –