到目前为止,我正在使用手动方式进行代理,这就是我处理标题的方式:
public abstract class UserClientBase<T> : ClientBase<T> where T : class
{
public UserClientBase()
{
string userName = Thread.CurrentPrincipal.Identity.Name;
MessageHeader<string> header = new MessageHeader<string>(userName);
OperationContextScope contextScope =
new OperationContextScope(InnerChannel);
OperationContext.Current.OutgoingMessageHeaders.Add(
header.GetUntypedHeader("String", "System"));
}
}
public class FooClient : UserClientBase<IFooService>, IFooService
{
public Foo Test()
{
return Channel.Test();
}
}
我的问题是.. 我该如何使用自动生成的代理?,就像这样:
using (FooServiceClient client = new FooServiceClient())
{
return await client.Test();
}
答案 0 :(得分:1)
与以前完全一样。几乎。
Using Client As New FooServiceClient, Scope As New OperationContextScope(Client.InnerChannel)
Dim Header As New MessageHeader(Of String)(Thread.CurrentPrincipal.Identity.Name)
OperationContext.Current.OutgoingMessageHeaders.Add(Header.GetUntypedHeader("String", "System"))
Return await client.Test();
End Using