Skip to main content

GlassFish and Vista - Interoperable out-of-the-box

Posted by arungupta on February 13, 2007 at 7:39 AM PST

GlassFish
v2 M4
and Windows
Vista
were released two
weeks ago
. I installed GlassFish M4 on my machine and Vista
Enterprise
on a different machine. In this blog, I explain the steps
followed to invoke a Web service deployed on GlassFish by Vista client and
vice versa.

First, lets deploy a service on GlassFish and invoke it using a client on
Vista.

  1. Using screencast
    WS#1
    , I developed a trivial Web service using NetBeans
    IDE
    and deployed on GlassFish.
  2. On Vista machine, I generated the client-side artifacts using the command:



    svcutil /config:Client.exe.config http://129.145.133.129:8080/WebApplication11/NewWebServiceService?wsdl
  3. Then I coded the client code to invoke the service endpoint as:



    using System;<br>
        using System.Collections.Generic;<br>
        using System.Text;<br>
        <br>
        namespace ConsoleApplication1<br>
        {<br>
        &nbsp;&nbsp; class Program<br>
        &nbsp;&nbsp; {<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        NewWebServiceClient client = new NewWebServiceClient();<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string response
        = client.sayHello(&quot;Duke&quot;);<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        Console.WriteLine(&quot;Response from WSIT endpoint: &quot; + response);<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
        &nbsp;&nbsp; }<br>
        }
  4. Next step is to compile the client code using the command:



    csc.exe /r:&quot;C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows
        Communication Foundation\System.ServiceModel.dll&quot;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /r:&quot;C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows
        Communication Foundation\System.Runtime.Serialization.dll&quot; <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Client.cs
        AddNumbersImplService.cs




    I wonder if there is a way by which csc.exe compiler can be
    made smarter to recognize WCF assemblies by default. But for now, I need to
    explicitly specify the assemblies during compilation otherwise the compiler
    throws bunch of errors like:



    NewWebServiceService.cs(100,63): error CS0234: The type or namespace
        name 'ServiceModel' does not exist in the namespace 'System' (are you
        missing an assembly reference?)
  5. After a successful compilation, invoking the client shows the result:



    Response from WSIT endpoint: Hello Duke

Now let's deploy a similar Web service on Vista and invoke it using
GlassFish.

  1. There are multiple ways a WCF Web service can be created from scratch but
    I find the following steps easiest. Create  service endpoint service.svc
    as:



    &lt;%@ServiceHost language=c# Debug=&quot;true&quot; Service=&quot;WCFEndpoint.Hello&quot;
        %&gt;<br>
        <br>
        using System.ServiceModel;<br>
        <br>
        namespace WCFEndpoint<br>
        {<br>
        &nbsp; &nbsp;[ServiceContract]<br>
        &nbsp; &nbsp;public interface IHello<br>
        &nbsp; &nbsp;{<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;[OperationContract]<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;string sayHello(string name);<br>
        &nbsp; &nbsp;}<br>
        <br>
        &nbsp; &nbsp;public class Hello : IHello<br>
        &nbsp; &nbsp;{<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;public string sayHello(string name)<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;{<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;return
        &quot;Hello &quot; + name;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;}<br>
        &nbsp; &nbsp;}<br>
        }
  2. In the same directory create Web.config as:



    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>
        &lt;configuration&gt;<br>
        &nbsp;&nbsp; &lt;system.serviceModel&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;behaviors&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;serviceBehaviors&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &lt;behavior name=&quot;MetadataBehavior&quot;&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &lt;serviceMetadata httpGetEnabled=&quot;true&quot; /&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &lt;/behavior&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/serviceBehaviors&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/behaviors&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;services&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;service
        behaviorConfiguration=&quot;MetadataBehavior&quot; name=&quot;WCFEndpoint.Hello&quot;&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &lt;endpoint address=&quot;&quot; binding=&quot;basicHttpBinding&quot;
        bindingConfiguration=&quot;&quot;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        name=&quot;Hello&quot; contract=&quot;WCFEndpoint.IHello&quot; /&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &lt;/service&gt;<br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/services&gt;<br>
        &nbsp;&nbsp; &lt;/system.serviceModel&gt;<br>
        &lt;/configuration&gt;
  3. I installed IIS after installing Vista so WCF extensions need to be
    explicitly registered as shown
    here
    .
  4. Create a virtual directory, say wsit, in IIS mapping to the
    directory where service.svc and Web.config are
    present. You should now see the default WCF/IIS page as shown
    here
    . The service endpoint now should be hosted at http://localhost/wsit/service.svc.
  5. Using screencast
    #WS2
    , create a JAX-WS client to invoke the Web service.

This is an example of a trivial interoperable Web service between GlassFish
M4 and Vista but the key fact is that, as a developer, this is provided as
out-of-the-box experience. No extra tweaks or no special configurations
required.

I plan to build upon this Web service by adding enterprise Web services
features such as Reliable Messaging, Security etc. and show how WSIT
enables interoperability with WCF.

Technorati: WSIT Web
Services
Interoperability
GlassFish Vista

Related Topics >>