[英]How to add soap header to auto-generated proxies in WCF?
So far I was doing proxies with the manual way and this is how I handled headers: 到目前为止,我使用手动方式进行代理,这是我处理标头的方式:
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();
}
}
My question is.. how can I do the that with auto-generated proxies?? 我的问题是.. 如何使用自动生成的代理? , like this:
, 像这样:
using (FooServiceClient client = new FooServiceClient())
{
return await client.Test();
}
Exactly the same way as you did before. 与您之前完全相同。 Almost.
几乎。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.