I'm relatively new to webservices and C# but not to programing (lots of experience in legacy systems).
I've got a closed loop system - I write the webservice and the consuming application - which is on a PDA.
Web service is published and for the PDA app, I use "add new web reference" feature in VS.
I can then use code like:
AppName.com.MyDomain.WebServiceName s = new AppNamecom.MyDomain.WebServiceName();
s.SomeMethod(Param1, Param2);
All is well...until I discover that I need to update one of the webmethods to take say 3 parameters when I used to take 2.
If I change the webservice and publish, all my existing PDA's will simply fail on the call until they get the new version of PDA software. With hundreds in the field, I can't update them all at once nor do I want to require them to update all at the same time.
Solution 1:
Add a version number to the webservice method so SomeMethod now has SomeMethodV2(1,2,3) Update PDA software to use s.SomeMethodV2
Solution 2: Copy the existing "webServiceName" to say WebServiceNameV2, which has SomeMethod(1,2,3) Change the PDA software to reference AppName.com.MyDomain.WebServiceNameV2 At some point when you know that no PDA's are using V1 anymore, shut down that web开发者_运维知识库service.
Both of these solutions have pro's & con's but i'm not convinced there are only two; there are probably more elegant ways to handle this situation ? Perhaps not by using the "add new web reference"
I'm using .net 2.0 for the PDA, .net 3.5 for the webservice; c# for both. I've not looked into it yet but I don't think I can use WCF with .net 2.0 on the PDA.
Andrew
I think a hybrid approach gives you the best of both worlds:
Before:
public interface IMyService
{
SomeResponse SomeMethod(object param1, object param2);
}
public class MyService : IMyService
{
public SomeResponse SomeMethod(object param1, object param2)
{
// do stuff
}
}
After:
public interface IMyService
{
SomeResponse SomeMethod(object param1, object param2);
}
public interface IMyService2
{
SomeResponse SomeMethod(object param1, object param2, object param3);
}
public class MyService : IMyService, IMyService2
{
public SomeResponse SomeMethod(object param1, object param2)
{
return SomeMethod(param1, param2, null);
}
public SomeResponse SomeMethod(object param1, object param2, object param3)
{
// do stuff
}
}
Your existing endpoint remains unchanged, because you are still using the same contract (interface), your new endpoint for go-forward/updated PDAs points to the new contract, and you don't have to copy/duplicate the service implementation -- just implement multiple contracts.
精彩评论