Convert WSE Example Code to WCF

I am new to both WSE and WCF, and I am trying to use a web service using WCF, but all the documentation examples are for VS2005 + WSE. This web service uses WS-Security 1.0. I added a link to the service through visual studio, but I don’t understand how to make the code equivalent 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);
+5
source share
1 answer

After a few experiments, I figured out how to convert this code. The key was to configure the bindings in the WCF proxy, which VS2008 does correctly.

  • Add a service link pointing to WSDL
  • App.config/Web.config system.serviceModel. TransportWithMessageCredential. :

            <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>
    
  • ,

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

TransportWithMessageCredential UsernameOverTransportAssertion WSE 3.0

+8

All Articles