Использование WCF CustomBinding SOAP 1.1 - PullRequest
1 голос
/ 11 марта 2020

Преобразовать wsHttpBinding SOAP 1.2 в BindingCustom SOAP 1.1

Код тега Web.config wsHttpBinding:

  <wsHttpBinding>
    <binding name="ServiceBinding" allowCookies="true" closeTimeout="01:01:50" openTimeout="01:01:05" receiveTimeout="01:10:05" sendTimeout="01:01:05" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="Transport">
        <transport clientCredentialType="None" /> 
      </security>
    </binding>
  </wsHttpBinding>

Тег CustomBinding:

  <customBinding>
    <binding name="WsHttpSoap11"  >
      <security authenticationMode="CertificateOverTransport" />
      <textMessageEncoding messageVersion="Soap11WSAddressing10" maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" />
      <httpsTransport authenticationScheme="None" allowCookies="true"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
    </binding>
  </customBinding>

Продолжение кода web.config:

<services>
  <service behaviorConfiguration="ServiceBehavior" name="WcfPecuaria.Service">
    <endpoint name="ServiceBinding" contract="WcfPecuaria.IService" address="" binding="customBinding" bindingConfiguration="WsHttpSoap11" behaviorConfiguration="WsdlEndpointBehavior" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="WsdlEndpointBehavior">
      <wsdlExtensions location="https://dominio.br/PecuariaWCFH/Service1.svc" singleFile="true"/>
      <!--<wsdlExtensions location="http://localhost:44339/Service1.svc" singleFile="true"/> -->
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" includeWindowsGroups="false" customUserNamePasswordValidatorType="CustomUserNameValidator.CustomUserNameValidator,App_Code" />
        <clientCertificate>
          <authentication customCertificateValidatorType="CustomUserNameValidator.CustomCertificateValidator,App_Code" certificateValidationMode="Custom" includeWindowsGroups="false" />
        </clientCertificate>
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>

Отправляя запрос в SoapUI любым способом, я получаю сообщение об ошибке:

HTTP/1.1 415 Cannot process the message because the content type 'application/soap+xml;charset=UTF- 
8;action="http://tempuri.org/ServiceContract/SendBuscaLotes"' was not the expected type 'text/xml; 
charset=utf-8'.
Server: Microsoft-IIS/8.5
Date: Wed, 11 Mar 2020 12:10:39 GMT
Content-Length: 0

1 Ответ

0 голосов
/ 12 марта 2020

Terrifi c. Учитывая, что вы решили этот тип проблемы самостоятельно, я хочу дать общее решение для этого. Как преобразовать встроенную привязку системы к настраиваемой привязке?
Пожалуйста, обратитесь к следующим сегментам кода.

WSHttpBinding binding = new WSHttpBinding();
        binding.Security.Mode = SecurityMode.Transport;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
        //Iterate over all binding elements constructed the binding.
        foreach (var item in binding.CreateBindingElements())
        {
            Console.WriteLine(item.ToString());
        }

Результат.
enter image description here
Тогда мы можем создать пользовательскую привязку,

  <customBinding>
    <binding name="WsHttpSoap11"  >
      <transactionFlow/>
      <textMessageEncoding />
      <httpsTransport/>
    </binding>
  </customBinding>

Не стесняйтесь, дайте мне знать, если есть что-то, с чем я могу помочь.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...