Web方法可以重载吗? [英] Can web methods be overloaded ?

查看:53
本文介绍了Web方法可以重载吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



网络方法是否可以超载?


支持不同数量的输入参数?

解决方案

john,是的,你可以但是你需要指定MessageName属性,而

作为WSDL的别名。这是一个例子。


<%@ WebService Language =" C#"类= QUOT;计算器" %>


使用System;

使用System.Web.Services;


公共类计算器:WebService {

// MessageName属性默认为此XML Web服务的添加

方法。

[WebMethod]

public int Add(int i,int j){

return i + j;

}

[WebMethod(MessageName =" Add2" ;)]

public int Add(int i,int j,int k){

return i + j + k;

} < br $>
}


-

Greg Ewing [MVP]
http://www.citidc.com

" john bailo" < JB **** @ vestcom.com>在消息中写道

news:d6 ****************************** @ news.teranew s。 com ...


web方法是否可以重载?

支持不同数量的输入参数?





没有Web服务方法不能重载。如果要公开

重载类方法,则必须使用WebMethodAttribute的

MessageName属性提供别名。


C#:[WebMethod(MessageName =" GetCustomerByID")]

VB.NET< WebMethod(MessageName:=" GetCustomerByID)>


希望这会有所帮助


Chris Taylor


" john bailo" < JB **** @ vestcom.com>在消息中写道

news:d6 ****************************** @ news.teranew s。 com ...


web方法是否可以重载?

支持不同数量的输入参数?


如果我想使用3个参数,


当我从客户端调用该方法时,


我使用Add或Add2作为我的方法吗?


或者是''别名''只是一个'化妆品'的名称,用于重载

添加功能?


" Greg Ewing [MVP]" < gewing@_NO_SPAM_gewing.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...

john,是的,你可以,但你需要指定MessageName属性,虽然
作为WSDL的别名。这是一个例子。

<%@ WebService Language =" C#"类= QUOT;计算器" %>

使用System;
使用System.Web.Services;

公共类计算器:WebService {
// MessageName属性默认为添加此XML Web服务
方法。
[WebMethod]
public int Add(int i,int j){
return i + j;
}
[WebMethod(MessageName =" Add2")]
public int Add(int i,int j,int k){
return i + j + k;
}
}

- Greg Ewing [MVP]
http://www.citidc.com

" john bailo" < JB **** @ vestcom.com>在消息中写道
新闻:d6 ****************************** @ news.teranew s.com ...


web方法是否可以重载?

支持不同数量的输入参数?





Can a web method be overloaded?

To support varying numbers of input parameters?

解决方案

john, yes you can but you need to specify the MessageName attribute though
as an alias for the WSDL. Here''s an example.

<%@ WebService Language="C#" Class="Calculator" %>

using System;
using System.Web.Services;

public class Calculator : WebService {
// The MessageName property defaults to Add for this XML Web service
method.
[WebMethod]
public int Add(int i, int j) {
return i + j;
}
[WebMethod(MessageName="Add2")]
public int Add(int i, int j, int k) {
return i + j + k;
}
}

--
Greg Ewing [MVP]
http://www.citidc.com
"john bailo" <jb****@vestcom.com> wrote in message
news:d6******************************@news.teranew s.com...


Can a web method be overloaded?

To support varying numbers of input parameters?



Hi,

No Web Service methods can not be overloaded. If you want to expose an
overloaded class method, you will have to provide a alias using the
MessageName property of the WebMethodAttribute.

C# : [WebMethod( MessageName="GetCustomerByID" )]

VB.NET <WebMethod( MessageName := "GetCustomerByID)>

Hope this helps

Chris Taylor

"john bailo" <jb****@vestcom.com> wrote in message
news:d6******************************@news.teranew s.com...


Can a web method be overloaded?

To support varying numbers of input parameters?



if I want to use 3 parameters,

when I call the method from a client,

do I use Add or Add2 as my method?

Or is an ''alias'' just a ''cosmetic'' name for the overloaded
Add function?

"Greg Ewing [MVP]" <gewing@_NO_SPAM_gewing.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...

john, yes you can but you need to specify the MessageName attribute though
as an alias for the WSDL. Here''s an example.

<%@ WebService Language="C#" Class="Calculator" %>

using System;
using System.Web.Services;

public class Calculator : WebService {
// The MessageName property defaults to Add for this XML Web service
method.
[WebMethod]
public int Add(int i, int j) {
return i + j;
}
[WebMethod(MessageName="Add2")]
public int Add(int i, int j, int k) {
return i + j + k;
}
}

--
Greg Ewing [MVP]
http://www.citidc.com
"john bailo" <jb****@vestcom.com> wrote in message
news:d6******************************@news.teranew s.com...


Can a web method be overloaded?

To support varying numbers of input parameters?




这篇关于Web方法可以重载吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆