Sunday, February 13, 2011

Calling authenticated WSE web service in Visual Studio 2008.

Hi All,

This time i was given a task to call a web service which was written in older technology WSE and as you all know that its obsolete and replaced by WCF services but still some old written services are to be used.

When i added the service reference in my application it auto generates the configuration file as shown below, but by using this configuration file i was not able to provide credentials to web service call.

<basicHttpBinding>
        <binding name="FsetServiceSoap" 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="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>


        </binding>
        <binding name="FsetServiceSoap1" 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="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>


so i replaced this basichttp binding with custom binding.


<customBinding>

        <binding name="FsetServiceSoap" >

          <textMessageEncoding messageVersion="Soap12WSAddressingAugust2004" />

          <security authenticationMode="UserNameOverTransport"></security>

          <httpsTransport/>

        </binding>

      </customBinding>

and when calling the web service passed the credentials and it worked like charm.

FsetServiceHeader header = new FsetServiceHeader();
FsetServiceSoapClient client = new FsetServiceSoapClient();
client.ClientCredentials.UserName.UserName = _userName;
client.ClientCredentials.UserName.Password = _password;
byte[] rawData = File.ReadAllBytes(_filePath);
TransmissionAcknowledgementType result = client.SendTransmission(header, SendType, rawData);

Hope it helps.

Happy coding.

Regards,
U

No comments: