我试图覆盖标头以在此WebService中调用 push 方法,但是定义中不存在IContextChannel InnerChannel参数。
我按照以下链接中的文章响应所指示的方式创建了SecurityHeader类: https://stackoverflow.com/a/16031437/11505984。但是我不明白InnerChannel的来源。
try
{
TransmissionService transmission = new TransmissionService();
using (new OperationContextScope(transmission.InnerChannel))
{
OperationContext.Current.OutgoingMessageHeaders.Add(
new SecurityHeader("UsernameToken-8", "12345/userID", "password123"));
transmission.publish(new Transmission());
}
}
catch(Exception e)
{
var message = e.Message;
}
我遇到以下错误:TransmissionService不包含InnerChannel的定义,也没有扩展方法。
有人可以告诉我我需要什么吗?
谢谢
答案 0 :(得分:0)
尝试将TransmissionService投射到IContextChannel:
try
{
TransmissionService transmission = new TransmissionService();
using (new OperationContextScope((IContextChannel) transmission))
{
OperationContext.Current.OutgoingMessageHeaders.Add(
new SecurityHeader("UsernameToken-8", "12345/userID", "password123"));
transmission.publish(new Transmission());
}
}
catch(Exception e)
{
var message = e.Message;
}
也许这些链接也会对您有帮助:
https://trycatch.me/adding-custom-message-headers-to-a-wcf-service-using-inspectors-behaviors/
https://github.com/NaveeenSemwal/add-a-custom-http-header-to-every-wcf-call
https://github.com/lamronby/wcfextrasplus