Thursday April 26, 2007
How to invoke a WSIT endpoint from a WCF client ?
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.
Program.cs
is shown in the main Visual Studio window.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.http://localhost:8080/WebApplication1/NewWebServiceService?wsdl).In the Main function of Program.cs, add the logic to invoke the generated proxy. The code looks like:usingSystem; using System.Collections.Generic; using System.Text; using ConsoleApplication1.localhost;
namespaceConsoleApplication1 { class Program { static void Main(string[] args) { NewWebServiceClient client = new NewWebServiceClient(); Console.WriteLine(client.sayHello("Duke")); } } }
Build", "Build
Solution" (default shortcut Ctrl+Shift+B).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
Posted by Arun Gupta in webservices | Comments[10]
|
|
|
|
|
Today's Page Hits: 983
Total # blog entries: 994