如何处理webservice版本中的参数变化

发布于 2024-11-17 21:53:58 字数 949 浏览 2 评论 0原文

我对 Web 服务和 C# 比较陌生,但对编程不太熟悉(在遗留系统方面有很多经验)。

我有一个闭环系统 - 我编写网络服务和消费应用程序 - 它位于 PDA 上。

Web 服务已发布,对于 PDA 应用程序,我在 VS 中使用“添加新的 Web 引用”功能。

然后我可以使用如下代码:

AppName.com.MyDomain.WebServiceName s = new AppNamecom.MyDomain.WebServiceName();
s.SomeMethod(Param1, Param2);

一切都很好...直到我发现我需要更新其中一个 webmethods 以获取 3 个参数,而我以前需要 2 个参数。

如果我更改 webservice 并发布,我所有现有的 PDA 都会在他们获得新版本的 PDA 软件之前,他们只会失败。由于现场有数百个,我无法一次更新所有这些,也不想要求他们同时更新所有。

解决方案 1:

向 Web 服务方法添加版本号,以便 SomeMethod 现在具有 SomeMethodV2(1,2,3) 更新 PDA 软件以使用 s.SomeMethodV2

解决方案 2: 将现有的“webServiceName”复制为 WebServiceNameV2,其中包含 SomeMethod(1,2,3) 将 PDA 软件更改为引用 AppName.com.MyDomain.WebServiceNameV2 当您知道不再有 PDA 使用 V1 时,请关闭该 Web 服务。

这两种解决方案都有其优点和优点。缺点,但我不相信只有两个;可能有更优雅的方法来处理这种情况?也许不是通过使用“添加新的 Web 引用”,

我使用 .net 2.0 作为 PDA,使用 .net 3.5 作为 Web 服务; c# 两者都适用。我还没有研究过它,但我认为我不能在 PDA 上将 WCF 与 .net 2.0 一起使用。

安德鲁

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 webservice.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

郁金香雨 2024-11-24 21:53:58

我认为混合方法可以让您两全其美:

之前:

public interface IMyService
{
    SomeResponse SomeMethod(object param1, object param2);
}

public class MyService : IMyService
{
    public SomeResponse SomeMethod(object param1, object param2)
    {
        // do stuff
    }
}

之后:

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
    }
}

您现有的端点保持不变,因为您仍在使用相同的合同(界面),前进/更新的 PDA 的新端点指向新合同,并且您不必复制/复制服务实现——只需实现多个合约即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文