First let's create a simple example project and install the grails-cxf plugin:
grails create-app example
grails install-plugin cxfNext let's create a service:
grails create-service exampleThis has created 2 files:
grails-app/services/example/ExampleService.groovy
and
test/unit/example/ExampleServiceTests.groovyThe first one is the one we need to modify so let's get to it:
package example
import javax.jws.*
@WebService(serviceName="ExampleService", name="Example")
class ExampleService {
static expose = [ 'cxfjax' ]
@WebMethod(operationName="sayHello")
String sayHello(@WebParam(name="name") String name) {
"Hello ${name}!"
}
}As you can see I've added every possible bit of information to customize the generated WSDL. With all that in place we can get the description of this service (WSDL) at http://localhost:8080/example/services/example?wsdl. Let's use that to create a .NET client. This time from command-line:
SET PATH=%PATH%;"C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin"
wsdl.exe http://localhost:8080/example/services/example?wsdlIn the first line we're expanding the system path so that all the tools are available from anywhere. In the second line we're generating a client for the web service we've created in Grails. Simple enough, right?
Let's create a simple console application and use this newly generated client:
Program.cs:
using System;
public class Progra {
public static void Main(String[] args) {
Console.WriteLine(new ExampleService().sayHello("John"));
}
}Let's compile everything from command-line:
set PATH=%PATH%;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
csc *.csAgain, no magic here. Once you've compiled everything run the application and bum! Everything works as expected :)
My guess is that CXF plugin didn't work just right out of the box because of some problems with default naming that CXF is using when auto-generating WSDL. With all the annotations in place everything seems to be working just fine.
I hope this will help someone. In case you'd like to fiddle with it yourself here's the example. in src/csharp you'll find the sources for the client along with a batch file to compile them.
Unfortunately when it comes to a more advanced scenario, like for example returning an array of domain objects from a service method the CXF plugin still fails to produce good enough WSDL to work with .NET. This is the case where XFire plugin shines best!
FYI: the same trick does not work with Axis2 plugin. The naming is all whacko. Things like
this$dist$set$2 and urn:this$dist$get$2 hurt the WSDL code generator so much it spits nothing out but a load of warnings.Have fun!










