1

Is it possible to change a parameter name of an asmx web service without breaking clients? For example, consider a legacy service which has a web method like so:

 [WebMethod]
 public string HelloWorld(string NAME)
 {
      return "Hello World and " + NAME;
 }

The legacy service web method has the parameter NAME, but I'd like to change this to 'Name' to follow coding guide-lines. Will this break existing clients?

4

1 回答 1

1

最简单的可能是添加一个新方法

 //New clients use this Maybe you put it in a new asmx file.
 [WebMethod]
 public string Hello_World(string FullName)
 {
      return HelloWorld(FullName);
 }

//Old clients use this.
[WebMethod]
 public string HelloWorld(string NAME)
 {
      return "Hello World and " + NAME;
 }

WCF 有方法名称和参数是一回事,但使用注释的 xml 是另一回事。我认为有一种方法可以创建可以与旧版 ASMX 客户端对话的 WCF 服务,我还没有尝试过。在这种情况下,您可以重命名所有方法和参数,并通过属性注释,跨线路维护 xml 的旧名称。

于 2013-04-24T15:02:39.257 回答