views:

39

answers:

2

My friend build a web service in java I build one in .net

I want them to implement the same interface

then in my program change the web.config to point to one or the other.

In my mind this would be done by implementing the same interface. Not sure how it would actually be done...

A: 

The subtle differences between ASP.NET and Java web services will make this a hard task.

An alternative might be to create an adapter service in front of them, which exposes the same semantic interface, and has service references to both.

This adapter service can be configured to pass on commands to either the Java one or the .NET one based on the same approach of modifying the web.config. IE:

[WebMethod]
public int AddTwoNumbers(int numberA, int numberB)
{
    if(useJavaService)
        return javaService.AddTwoNumbers(numberA, numberB);
    else
        return dotnetService.AddTwoNumbers(numberA, numberB);
}

Your application can target this wrapper service, so from your application's perspective you would simply call:

int result = theService.AddTwoNumbers(5, 10);

and your application won't know if its going to hit the Java one or the .NET one.

Michael Shimmins
How is this adapter service doing anything that the client code can't do? You're making an identical function call in both cases. All you've done is slowed things down due to an additional round of processing at the adapter.
Yuliy
The client may invoke AddTwoNumbers in many places - rather that duplicating the service resolution login each time, the client is able to focus on getting things done rather than worrying about underlying service plumbing.
Michael Shimmins
OK fine. Put this in a utility method in the client. Don't toss a web server in front of it!
Yuliy
A: 

Perhaps the safest way would be to generate the interface from WSDL. Describe your service(s) in a WSDL document then use 'wsimport -d src WSDL_file' (in Java).

Chuk Lee