开发者

Can VS.NET consume Java WS without generating wrapper structures?

When defining a simple web service in Java (Eclipse) and consuming the service in Visual Studio, the generated code contains a request and response structure for each service method. The generated client interface has methods that accept the request structure and return the valu开发者_StackOverflow社区e from the response structure.

For instance, if I have a service class SimpleTest with a method add(int a, int b), I get the following generated interface (annotations removed):

public interface ISimpleTest
{
    MyNamespace.WebServiceProxy.addResponse add(
        MyNamespace.WebServiceProxy.addRequest request);
}

However, if I create essentially the same class as a WCF web service, the code generates the following interface:

public interface ISimpleTest 
{                
    int Add(int a, int b);
}

I'd like to figure out if there's a way to avoid using the wrapper classes when consuming a Java service. Would defining datatypes in an XSD allow this or will .NET always generate these wrappers when consuming a non-.NET service? We'd like to bypass the generated client and implement the interface ourselves (without the wrappers). Is this possible?


You can definitely do this using WCF. You should be able to define your interface on the client side like so:

[ServiceContract]
public interface ISimpleTest
{
    [OperationContract]
    int Add(int a, int b);
}

From there, you can configure the implementation of your client through the client config or through code.


If I had to guess it is because Visual Studio for an external web service (Java, Perl, Ruby, etc) needs to go download the WSDL from that service and then generate the .NET stubs based on the WSDL which is the interface of all web services.

With a WCF Web Service it already has access to the classes etc for proxying so it doesn't need to generate the stubs and skeletons to call the web service.

This is just a guess though...

The only way to do it without the wrapper is if you created all the SOAP requests responses yourself and sent them over raw HTTP to the web service. This is messy code and the whole reason the .NET wrapper generator exists to shield you from that mess!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜