Wednesday, March 5, 2008

Testing WCF Services using groovyWS (Apache CXF)

I wanted to use groovyWS to test my WSDL-first .Net WCF web services. By default, WCF doesn't publish its WSDL, it doesn't publish a flat WSDL, and the recommended WsHttpBinding binding makes groovyWS unhappy. Once you work around these things, it is possible to very conveniently write independent dynamic tests for your services.

Since it took a while to collect all this information, I thought I would post my result: a WCF ping service that is interoperable with a groovyWS (i.e. Apache CXF) client.

The steps I took:

  1. Use GroovyWS to model my service. (groovy mockup\pingserver in one window and groovy pingclient in another)
  2. Captured the WSDL it generated (wget -O Ping.wsdl http://localhost:7020/Ping?wsdl)
  3. Wrote a .bat program to use the WCF svcutil.exe with XMLSerialization to generate marshaling code from the WSDL, and sed to remove generated ReplyAction="*" per operation so that it will properly expose information when it publishes its WSDL
  4. Use the included boiler plate code to do the self hosting (i.e. standalone server) with the BasicHttpBinding, and used the FlatWsdl() class, which along with proper namespace annotations to allow generation of a "flat wsdl".
  5. Appended a "ServiceBehavior" class which implements an interface generated from the WSDL, whose operations stubs can be generated from within Visual Studio by selecting the interface name, right click -> "Implement Interface"
All of this is bundled in a VS solution.

Prerequisites:
  1. groovy zip distribution
  2. groovyWS standalone jar (goes in lib dir)
  3. .Net Framework 3.0
  4. .Net Framework 3.0 WCF/WPF extensions
References:

Simple WCF Example
Improving WCF Interoperability: Flattening your WSDL
eliminating http://tempuri.org in wsdl
Getting started with groovyWS

Update (6 March): Java/.Net interoperability interviews with various SOAP project spokespersons

2 comments:

paulk said...

Nice writeup - I am doing something similar myself shortly, so good to see.

Erik Pogi said...

Nice once. There is also a .NET tool which you might be interested in. It works for both WCF and Web services

You can find it here: http://geekswithblogs.net/Erik/archive/2009/04/02/130664.aspx