简体   繁体   中英

Using WCF CustomBinding SOAP 1.1

Convert wsHttpBinding SOAP 1.2 to BindingCustom SOAP 1.1

Code Web.config tag 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>

tag 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>

Continuation of the code 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>

Making request in SoapUI in any method I have the error response:

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

Terrific. Given that you have solved this type of issue by yourself, I want to give a common solution to this. How to transform the built-in system-binding to custom binding?
Please refer to the below code segments.

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());
        }

Result.
在此处输入图片说明
Then we can construct the custom binding,

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

Feel free to let me know if there is anything I can help with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM