X

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

Guest Author
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;

    using System.Collections.Generic;

    using System.Text;


    namespace ConsoleApplication1

    {

       class Program

       {

           static void Main(string[] args)

           {

              
    NewWebServiceClient client = new NewWebServiceClient();

               string response
    = client.sayHello("Duke");

              
    Console.WriteLine("Response from WSIT endpoint: " + response);

           }

       }

    }
  4. Next step is to compile the client code using the command:

    csc.exe /r:"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.0\\Windows
    Communication Foundation\\System.ServiceModel.dll"

            /r:"C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.0\\Windows
    Communication Foundation\\System.Runtime.Serialization.dll"

            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:

    <%@ServiceHost language=c# Debug="true" Service="WCFEndpoint.Hello"
    %>


    using System.ServiceModel;


    namespace WCFEndpoint

    {

       [ServiceContract]

       public interface IHello

       {

           [OperationContract]

           string sayHello(string name);

       }


       public class Hello : IHello

       {

           public string sayHello(string name)

           {

               return
    "Hello " + name;

           }

       }

    }
  2. In the same directory create Web.config as:

    <?xml version="1.0" encoding="utf-8"?>

    <configuration>

       <system.serviceModel>

           <behaviors>

               <serviceBehaviors>

                  
    <behavior name="MetadataBehavior">

                       
    <serviceMetadata httpGetEnabled="true" />

                  
    </behavior>

               </serviceBehaviors>

           </behaviors>

           <services>

               <service
    behaviorConfiguration="MetadataBehavior" name="WCFEndpoint.Hello">

                  
    <endpoint address="" binding="basicHttpBinding"
    bindingConfiguration=""

                      
    name="Hello" contract="WCFEndpoint.IHello" />

              
    </service>

           </services>

       </system.serviceModel>

    </configuration>
  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

Join the discussion

Comments ( 1 )
  • Arun Gupta's Blog Tuesday, July 10, 2007
    [Trackback] GlassFish V2 beta3 is now available. I take this opportune moment for a follow up entry showing how a Reliable WSIT endpoint can be invoked from WCF client and vice versa. WSIT is already integrated in GlassFish V2. The first...
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha