Converting WSE example code to WCF
Asked Answered
E

1

5

I am new to both WSE and WCF and I am trying to consume a web service using WCF but all the example documentation is for VS2005 + WSE. This web service uses WS-Security 1.0. I have added a service reference through visual studio but I am at a loss on how to do the equivalent of the code below in WCF:

// 1. Initialize the web service proxy
PartnerAPIWse integrationFramework = new PartnerAPIWse();

// 2. Set the username/password. This is using the Username token of WS-Security 1.0
UsernameTokenProvider utp = new UsernameTokenProvider("username", "password");
integrationFramework.SetClientCredential<UsernameToken>(utp.GetToken());

// 3. Declare the policy
Policy policy = new Policy(new UsernameOverTransportAssertion());
integrationFramework.SetPolicy(policy);
Emendation answered 22/4, 2009 at 18:59 Comment(3)
For future reference: WSE is obsolete. All new web service development should be done using WCF, and WSE code should be retired ASAP.Stereogram
Some companies have a huge investment in WSE. It's not always a commercially sound decision to abandon a particular technology generation because the vendor has put something new out.Varden
This question and answer are helpful; however, in some cases, the resulting security header lacks a "nonce" and other critical elements / attributes. The following question and answer address this problem: #3103193Flotow
E
8

After spending a day doing some experimentation I figured out how to convert this code. The key was setting up the bindings on the WCF proxy that VS2008 makes correctly.

  1. Add a service reference pointing to the WSDL
  2. Open App.config / Web.config and locate the system.serviceModel section. Change the security mode on the default soapbinding to be TransportWithMessageCredential. Here is what my file looked like after the change:

            <basicHttpBinding>
            <binding name="SoapBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:10: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="TransportWithMessageCredential">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    
  3. Change the example code above to look like this

    Dim integrationFramework As New SoapClient()
    integrationFramework.ClientCredentials.UserName.UserName = "username"
    integrationFramework.ClientCredentials.UserName.Password = "password"
    

TransportWithMessageCredential is equivalent to UsernameOverTransportAssertion policy under WSE 3.0

Emendation answered 23/4, 2009 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.