Monday 1 February 2010

Fix for Error: "The provided URI scheme 'https' is invalid; expected 'http'. Parameter name: via." when calling Web Service in SAP

Today I got an exception after using the default bindings generated by the .NET svcutil.exe tool. This occurred as the tool incorrectly detected that it should be using an httpsTransport, and we didn’t have https internally. This was because the SAP wsdl supports both https and http bindings.

To get around this issue, I changd the binding to use 'security mode="TransportCredentialOnly"':

<binding name="Binding_T_HTTPS_A_HTTP_Z_CONTRACT_FIND_CE_ERP">
          <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
              messageVersion="Soap11" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          </textMessageEncoding>
          <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
              maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Basic"
              bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
              realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
              useDefaultWebProxy="true" requireClientCertificate="false" />
        </binding>

I changed it to use a basic authentication proxy, and it works (not secure – but this is for an internal dev box, not using https). This suits my purpose:

<basicHttpBinding>
        <binding name="SAPBasicHttpBinding" closeTimeout="00:01:00"
  openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
  allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
  maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
  messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
  useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="TransportCredentialOnly" >
            <transport clientCredentialType="Basic" proxyCredentialType="Basic"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>

2 comments:

Chirag Bhatt said...

I will be really grateful if you can provide me .net code to use the given WSDL.

Chirag Bhatt said...

Please also specify where to provide the username & password ?