就是命名冲突,在一个namespace里面有同名的类型。 可以给这些同名的类型指定不同的命名空间。通过XmlType和XmlRoot /// <summary> /// Summary description for Service1 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class Service1 : System.Web.Services.WebService {
[WebMethod] public string HelloWorld(HWA a, HWB b) { //XmlQualifiedName code = new XmlQualifiedName("Client.AuthenticationFailure", "http://schemas.xmlsoap.org/soap/envelope/"); //SoapException ex = new SoapException("this is error", code, "this is action");
[XmlType(Namespace = "http://tempuri.org/HWA")] [XmlRoot(Namespace = "http://tempuri.org/HWA")] public enum Field { aaa, bbb, ccc } } public class HWB { public Field field; [XmlType(Namespace = "http://tempuri.org/HWB")] [XmlRoot(Namespace = "http://tempuri.org/HWB")] public enum Field { a111, a222, a333 } } 参考: http://msdn.microsoft.com/en-us/magazine/cc164122.aspx
可以给这些同名的类型指定不同的命名空间。通过XmlType和XmlRoot
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(HWA a, HWB b)
{
//XmlQualifiedName code = new XmlQualifiedName("Client.AuthenticationFailure", "http://schemas.xmlsoap.org/soap/envelope/");
//SoapException ex = new SoapException("this is error", code, "this is action");
//throw ex;
return ((int)a.field + (int)b.field).ToString();
}
}
public class HWA
{
public Field field;
[XmlType(Namespace = "http://tempuri.org/HWA")]
[XmlRoot(Namespace = "http://tempuri.org/HWA")]
public enum Field
{
aaa,
bbb,
ccc
}
}
public class HWB
{
public Field field;
[XmlType(Namespace = "http://tempuri.org/HWB")]
[XmlRoot(Namespace = "http://tempuri.org/HWB")]
public enum Field
{
a111,
a222,
a333
}
}
参考:
http://msdn.microsoft.com/en-us/magazine/cc164122.aspx
顺便问一句,XMLType和XMLRoot需要导入什么命名空间,直接写出错
顺便问一句,XMLType和XMLRoot需要导入什么命名空间,直接写出错已经找到了。谢谢!using System.Xml.Serialization;
你好,我还有一个问题想请教一下,就对于你这个例子来说,HelloWorld方法,返回的xml数据,HelloWorldReponse下的第一个标签是HelloWorldResult,怎么样才能改变HelloWorldResult这个名字,改为自己想要的?
谢谢!!!
[WebMethod]
[return: XmlElement(ElementName = "myResult")]
public string HelloWorld([XmlElement(ElementName = "myHwa")]HWA a, HWB b)
{
//XmlQualifiedName code = new XmlQualifiedName("Client.AuthenticationFailure", "http://schemas.xmlsoap.org/soap/envelope/");
//SoapException ex = new SoapException("this is error", code, "this is action"); //throw ex;
return ((int)a.field + (int)b.field).ToString();
}