【问题标题】:Where does IContextChannel client.InnerChannel come from this WSDL?IContextChannel client.InnerChannel 来自这个 WSDL?
【发布时间】:2019-05-15 19:12:07
【问题描述】:

我正在尝试覆盖标头以在此 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 的定义并且没有扩展方法。

谁能解释一下我需要什么?

谢谢

【问题讨论】:

    标签: c# .net web-services wsse


    【解决方案1】:

    尝试将 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

    https://github.com/vh-vahan/WcfSecurityHeader

    https://github.com/melomenic/wcfheaderinjectionbehavior

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多