GlassFish and Vista - Interoperable out-of-the-box
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.
- Using screencast
WS#1, I developed a trivial Web service using NetBeans
IDE and deployed on GlassFish. - 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 - 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>
class Program<br>
{<br>
static void Main(string[] args)<br>
{<br>
NewWebServiceClient client = new NewWebServiceClient();<br>
string response
= client.sayHello("Duke");<br>
Console.WriteLine("Response from WSIT endpoint: " + response);<br>
}<br>
}<br>
} - 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"<br>
/r:"C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows
Communication Foundation\System.Runtime.Serialization.dll" <br>
Client.cs
AddNumbersImplService.cs
I wonder if there is a way by whichcsc.execompiler 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?) - 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.
- There are multiple ways a WCF Web service can be created from scratch but
I find the following steps easiest. Create service endpointservice.svc
as:
<%@ServiceHost language=c# Debug="true" Service="WCFEndpoint.Hello"
%><br>
<br>
using System.ServiceModel;<br>
<br>
namespace WCFEndpoint<br>
{<br>
[ServiceContract]<br>
public interface IHello<br>
{<br>
[OperationContract]<br>
string sayHello(string name);<br>
}<br>
<br>
public class Hello : IHello<br>
{<br>
public string sayHello(string name)<br>
{<br>
return
"Hello " + name;<br>
}<br>
}<br>
} - In the same directory create
Web.configas:
<?xml version="1.0" encoding="utf-8"?><br>
<configuration><br>
<system.serviceModel><br>
<behaviors><br>
<serviceBehaviors><br>
<behavior name="MetadataBehavior"><br>
<serviceMetadata httpGetEnabled="true" /><br>
</behavior><br>
</serviceBehaviors><br>
</behaviors><br>
<services><br>
<service
behaviorConfiguration="MetadataBehavior" name="WCFEndpoint.Hello"><br>
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration=""<br>
name="Hello" contract="WCFEndpoint.IHello" /><br>
</service><br>
</services><br>
</system.serviceModel><br>
</configuration> - I installed IIS after installing Vista so WCF extensions need to be
explicitly registered as shown
here. - Create a virtual directory, say
wsit, in IIS mapping to the
directory whereservice.svcandWeb.configare
present. You should now see the default WCF/IIS page as shown
here. The service endpoint now should be hosted athttp://localhost/wsit/service.svc. - 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
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 1010 reads





