如何使用重载方法访问Web服务 [英] How to access a web service with overloaded methods
问题描述
我正在尝试在Web服务中使用重载方法,但是在Visual Studio 2005中尝试添加Web引用"时出现了System.InvalidOperationException异常(这是相关的代码段):
I'm trying to have overloaded methods in a web service but I am getting a System.InvalidOperationException when attempting "Add Web Reference" in Visual Studio 2005 (here's the relevant snippets of code):
public class FileService : System.Web.Services.WebService
{
private static readonly MetaData[] EmptyMetaData = new MetaData[0];
public FileService()
{
// a few innocent lines of constructor code here...
}
[WebMethod(MessageName = "UploadFileBasic",
Description = "Upload a file with no metadata properties")]
public string UploadFile(string trimURL
, byte[] incomingArray
, string fileName
, string TrimRecordTypeName)
{
return UploadFile(trimURL
, incomingArray
, fileName
, TrimRecordTypeName
, EmptyMetaData);
}
[WebMethod(MessageName = "UploadFile",
Description = "Upload a file with an array of metadata properties (Name/Value pairs)")]
public string UploadFile( string trimURL
, byte[] incomingArray
, string FileName
, string TrimRecordTypeName
, MetaData[] metaDataArray)
{
// body of UploadFile function here
我认为在WebMethod属性上提供其他MessageName属性可以解决此问题,但这是我得到的全部错误消息:
I thought supplying a different MessageName property on the WebMethod attribute would fix this problem but here is the entire error message I get:
System.String UploadFileBasic(System.String,Byte [],System.String,System.String)和System.String UploadFile(System.String,Byte [],System.String,System.String)都使用该消息名称为"UploadFileBasic".使用WebMethod定制属性的MessageName属性可以为方法指定唯一的消息名称.
Both System.String UploadFileBasic(System.String, Byte[], System.String, System.String) and System.String UploadFile(System.String, Byte[], System.String, System.String) use the message name 'UploadFileBasic'. Use the MessageName property of the WebMethod custom attribute to specify unique message names for the methods.
Web服务编译正常;我看不到这里有什么问题.
The web service compiles OK; I cannot see what is wrong here.
推荐答案
我的建议是不要使用重载的方法名称. WSDL中没有这样的概念,那为什么要麻烦呢?
My suggestion is to not use overloaded method names. There is no such concept in WSDL, so why bother?
这篇关于如何使用重载方法访问Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!