Откуда берется IContextChannel client.InnerChannel из этого WSDL?

Я пытаюсь перезаписать заголовки, чтобы метод 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 и метода расширения.

Может кто-нибудь объяснить мне, что мне нужно?

Спасибо


person Abraham SA    schedule 15.05.2019    source источник


Ответы (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

person Ilya Belitser    schedule 13.02.2020