X

How to invoke a WSIT endpoint from a WCF client ?

Guest Author
You've developed a reliable, secure transactional and interoperable Web
service using Web Services Interoperability
Technology
(WSIT, aka Project Tango)
plug-in in
NetBeans 5.5.1
and deployed on GlassFish v2.
NetBeans IDE provide a very seamless experience to build such a Web service. The
primary goal of WSIT is to provide first-class interoperability with
Windows
Communication Foundation
(WCF), the Web services component of
.NET 3.0 framework. Once the
Web service is deployed, you'd like to invoke this Web service by writing a
client using
Visual Studio
. It's not straight forward to do so today and this entry
highlights the steps required to do that.



  1. If not already done, create a reliable WSIT endpoint and deploy on GlassFish v2 following the


    screencast #ws3
    .

  2. For creating a WCF client, install the following software

    1. If not using Vista, then install


      .NET 3.0 Framework runtime
      .

    2. Microsoft Visual Studio 2005 Professional Edition (available via MSDN)

      - There are additional requirements for Express editions (free

      lightweight versions of Visual Studio)


    3. Microsoft Visual Studio 2005 Professional Edition SP1


    4. Microsoft Visual Studio 2005 Professional Edition SP1 Update



    5. Visual Studio 2005 Extensions for .NET 3.0 Framework (WCF & WPF), Nov 2006

      CTP
      - For Express editions,


      Windows Vista SDK
      is required as well for WCF scenarios.



  3. Start Visual Studio

  4. Create a new Visual C#, Windows, Console Application. Program.cs

    is shown in the main Visual Studio window.

  5. In Solution Explorer, right-click on the project name and select "Add

    Service Reference ...
    ". This is the big difference. If you select "Add

    Web Reference ...
    ", then this creates a proxy and app.config

    for .NET 2.0 framework. But WSIT is about interoperability with .NET 3.0

    framework.

  6. Specify the location of the WSIT endpoint, in our case (http://localhost:8080/WebApplication1/NewWebServiceService?wsdl).


  7. In the Main function of Program.cs, add the logic to invoke the generated proxy. The code looks like:
    using System;
    using System.Collections.Generic;
    using
    System.Text;
    using ConsoleApplication1.localhost;

    namespace ConsoleApplication1
    {class Program{static void Main(string[] args)
    {NewWebServiceClient client = new NewWebServiceClient();Console.WriteLine(client.sayHello("Duke"));
    }
    }
    }


  8. Build the solution by selecting "Build", "Build

    Solution
    " (default shortcut Ctrl+Shift+B).

  9. Run ConsoleApplication1\\bin\\Debug\\ConsoleApplication1.exe.

    This will make a request to WSIT endpoint and get a response back.

The generated app.config file looks like:


<?xml version="1.0" encoding="utf-8" ?>
<
configuration>
<
system.serviceModel>
<
bindings>
<
customBinding>
<
binding name="NewWebServicePortBinding">
<
reliableSession acknowledgementInterval="00:00:00.2000000" flowControlEnabled="true"
inactivityTimeout="00:10:00" maxPendingChannels="4" maxRetryCount="8"
maxTransferWindowSize="8" ordered="true" />
<
textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap11WSAddressing10" writeEncoding="utf-8">
<
readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</
textMessageEncoding>
<
httpTransport manualAddressing="false" maxBufferPoolSize="524288"maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</
binding>
</
customBinding>
</
bindings>
<
client>
<
endpoint address="http://localhost:8080/WebApplication1/NewWebServiceService"
binding="customBinding" bindingConfiguration="NewWebServicePortBinding"
contract="ConsoleApplication1.localhost.NewWebService" name="NewWebServicePort" />
</
client>
</
system.serviceModel>
</
configuration
>

Here are the SOAP messages that get exchanged over the wire:

====[com.sun.xml.ws.assembler.server:request]====
<?xml version="1.0" ?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</a:Action>
<a:MessageID>urn:uuid:3429a390-96df-4f26-bd8c-fc85bd8f1858</a:MessageID>
<a:To s:mustUnderstand="1">http://localhost:8080/WebApplication1/NewWebServiceService</a:To>
</s:Header>
<s:Body>
<CreateSequence xmlns="http://schemas.xmlsoap.org/ws/2005/02/rm">
<AcksTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</AcksTo>
<Offer>
<Identifier>urn:uuid:402432c9-b191-4912-a04a-69bbdbd1b2d3</Identifier>
</Offer>
</CreateSequence>
</s:Body>
</s:Envelope>
============
====[com.sun.xml.ws.assembler.server:response]====
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequenceResponse</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:b51f92ee-9ab9-4a90-a61e-d5dd3a77a0f9</MessageID>
<RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:3429a390-96df-4f26-bd8c-fc85bd8f1858</RelatesTo>
</S:Header>
<S:Body>
<ns2:CreateSequenceResponse xmlns:ns6="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ns5="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns4="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://schemas.microsoft.com/ws/2006/05/rm" xmlns:ns2="http://schemas.xmlsoap.org/ws/2005/02/rm">
<ns2:Identifier>uuid:d01cff2f-9192-4672-942b-2ec284a93802</ns2:Identifier>
<ns2:Accept>
<ns2:AcksTo>
<ns4:Address>http://localhost:8080/WebApplication1/NewWebServiceService</ns4:Address>
</ns2:AcksTo>
</ns2:Accept>
</ns2:CreateSequenceResponse>
</S:Body>
</S:Envelope>
============
====[com.sun.xml.ws.assembler.server:request]====
<?xml version="1.0" ?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<r:Sequence s:mustUnderstand="1">
<r:Identifier>uuid:d01cff2f-9192-4672-942b-2ec284a93802</r:Identifier>
<r:MessageNumber>1</r:MessageNumber>
</r:Sequence>
<a:Action s:mustUnderstand="1">sayHello</a:Action>
<a:MessageID>urn:uuid:d9c8b864-f236-40ad-a4c0-72c42565855f</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">http://localhost:8080/WebApplication1/NewWebServiceService</a:To>
</s:Header>
<s:Body>
<sayHello xmlns="http://test/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<name xmlns="">Duke</name>
</sayHello>
</s:Body>
</s:Envelope>
============
====[com.sun.xml.ws.assembler.server:response]====
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://test/NewWebService/sayHelloResponse</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:9091661c-c817-4411-b8aa-7f4f937162da</MessageID>
<RelatesTo xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:d9c8b864-f236-40ad-a4c0-72c42565855f</RelatesTo>
<ns2:Sequence xmlns:ns4="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://schemas.microsoft.com/ws/2006/05/rm" xmlns:ns2="http://schemas.xmlsoap.org/ws/2005/02/rm">
<ns2:Identifier>urn:uuid:402432c9-b191-4912-a04a-69bbdbd1b2d3</ns2:Identifier>
<ns2:MessageNumber>1</ns2:MessageNumber>
</ns2:Sequence>
<ns2:AckRequested xmlns:ns4="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://schemas.microsoft.com/ws/2006/05/rm" xmlns:ns2="http://schemas.xmlsoap.org/ws/2005/02/rm">
<ns2:Identifier>urn:uuid:402432c9-b191-4912-a04a-69bbdbd1b2d3</ns2:Identifier>
</ns2:AckRequested>
<ns2:SequenceAcknowledgement xmlns:ns4="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://schemas.microsoft.com/ws/2006/05/rm" xmlns:ns2="http://schemas.xmlsoap.org/ws/2005/02/rm">
<ns2:Identifier>uuid:d01cff2f-9192-4672-942b-2ec284a93802</ns2:Identifier>
<ns2:AcknowledgementRange Upper="1" Lower="1"></ns2:AcknowledgementRange>
</ns2:SequenceAcknowledgement>
</S:Header>
<S:Body>
<ns2:sayHelloResponse xmlns:ns2="http://test/">
<return>Hello Duke</return>
</ns2:sayHelloResponse>
</S:Body>
</S:Envelope>
============

The same programming model will work for creating a WCF client if you add
security or transactions support on the WSIT endpoint.

Technorati: wsit
glassfish
webservices
vista
wcf

visualstudio

Join the discussion

Comments ( 10 )
  • legolas wood Monday, April 30, 2007
    Hi
    I saw your screencasts and they are very good.
    can you please create a zip archive of your screencaset ?
    I really need to download them and study them
    during my trips and i have no internet access in train .
    looking for your comment.
    Thanks
  • Phil Wednesday, July 4, 2007
    Hi Arun,
    Have you try to encrypt the response body in this simple scenario?
    Thanks,
    Phil
  • Arun Wednesday, July 4, 2007
    Legolas, I'll work on providing an offline version of the screencasts later this week.
    Thanks,
    -Arun
  • Arun Wednesday, July 4, 2007
    Phil, Yes, we've tried much more complex scenario and they worked like a charm. Read more about our participation at Microsoft's plugfest at: http://blogs.sun.com/arungupta/tags/plugfest
  • Arun Gupta Tuesday, August 21, 2007

    All the screencasts are now available for off-line viewing at:

    http://wiki.glassfish.java.net/Wiki.jsp?page=Screencasts


  • DSK Monday, October 13, 2008

    Hi! i created a web service as explained in the screencast ws3. Next i tried creating the WCF client. I am able to view the app.config file. However im unaable to get the response as "Hello Duke" back from the web service. It will be great if you could tell me how to. Thanks a lot!


  • Arun Gupta Monday, October 13, 2008

    DSK, are you getting some error ?


  • DSK Monday, October 13, 2008

    I got the following error:

    The type or namespace name 'localhost' does not exist in the namespace 'ConsoleApplication1' (are you missing an assembly reference?)

    I was prompted to enter the header as:

    "using ConsoleApplication1.ServiceReference1" by default. When i tried this there was no error but im not getting the response back from the web service. Please tell me what i should do.

    Thanks a lot for your help!


  • DSK Monday, October 20, 2008

    Hi!

    Ive bee anxiously awaiting your response to my query. It would be great if you could help me out! Please give me a solution to my problem.Thanks!


  • Arun Gupta Friday, October 24, 2008

    DSK, please post your question to users@metro.dev.java.net for a wider audience.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha