Предотвратить добавление заголовка SOAP "To" - PullRequest
0 голосов
/ 06 декабря 2018

У меня проблема с заголовком SOAP, созданным в моем клиенте C #.Сервер отправляет обратно ошибку

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <s:Header xmlns:s="http://www.w3.org/2003/05/soap-envelope" />
  <soap:Body>
    <soap:Fault>
      <soap:Code>
        <soap:Value>soap:MustUnderstand</soap:Value>
      </soap:Code>
      <soap:Reason>
        <soap:Text xml:lang="en">MustUnderstand headers: [{http://www.w3.org/2005/08/addressing}To] are not understood.</soap:Text>
      </soap:Reason>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

У меня сложилось впечатление, что я удаляю все заголовки SOAP с помощью следующего кода.

internal class CustomMessageInspector : IEndpointBehavior, IClientMessageInspector
{
    public object BeforeSendRequest( ref Message request, IClientChannel channel )
    {
        request.Headers.Clear();
        return null;
    }
    ...
 }

Однако после активации System.ServiceModel.MessageLogging в app.config, ( WCF - Проверка отправляемых / получаемых сообщений? ), я вижу, что сервер правильный- вот, есть заголовок «Кому», для которого «mustUnderstand» имеет значение 1:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:To s:mustUnderstand="1">https://ws-single-transactions-int-bp.nmvs.eu:8443/WS_SINGLE_TRANSACTIONS_V1/SinglePackServiceV30</a:To>
</s:Header>

Есть какие-нибудь мысли, как я могу предотвратить добавление этого заголовка?

Большое спасибо.

1 Ответ

0 голосов
/ 06 декабря 2018

В случае, если это поможет кому-то еще, я нашел решение.На самом деле Николас Джанноне предоставил весь необходимый код здесь WSHttpBinding в .NetStandard или .NET core .Что мы можем сделать, это заменить WSHttpBinding пользовательской привязкой на основе WSHttpBinding, а затем заменить TextMessageEncodingBindingElement на другую без адресации.Вот код:

    string endPoint = myConfig.SinglePackServicesEndPoint;

    //Defines a secure binding with certificate authentication
    WSHttpBinding binding = new WSHttpBinding();
    binding.Security.Mode = SecurityMode.Transport;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

    // create a new binding based on the existing binding
    var customTransportSecurityBinding = new CustomBinding( binding );
    // locate the TextMessageEncodingBindingElement - that's the party guilty of the inclusion of the "To"
    var ele = customTransportSecurityBinding.Elements.FirstOrDefault( x=>x is TextMessageEncodingBindingElement );
    if( ele != null )
    {
        // and replace it with a version with no addressing
        // replace {Soap12 (http://www.w3.org/2003/05/soap-envelope) Addressing10 (http://www.w3.org/2005/08/addressing)}
        //    with {Soap12 (http://www.w3.org/2003/05/soap-envelope) AddressingNone (http://schemas.microsoft.com/ws/2005/05/addressing/none)}
        int index = customTransportSecurityBinding.Elements.IndexOf( ele );
        var textBindingElement = new TextMessageEncodingBindingElement
        {
            MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None)
        };
        customTransportSecurityBinding.Elements[index] = textBindingElement;
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...