如何在webservice传输复杂的数据,如xml数据(方法的返回类型)

happydayandday 2003-10-20 10:23:50
问题如题,各位帮忙啊
...全文
649 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqchen79 2003-10-23
  • 打赏
  • 举报
回复
...
[WebMethod]
[XmlAnyElement]
public XmlElement CallXml(int num)
{
...
return XDoc.DocumentElement;
}
happydayandday 2003-10-22
  • 打赏
  • 举报
回复
像上面我放回一个xml文档我该怎么做阿
ETstudio 2003-10-22
  • 打赏
  • 举报
回复
public dataset dddd()
{
DataSet ds=new DataSet;
ds.readXml(输入xml);
}
Rossetti 2003-10-22
  • 打赏
  • 举报
回复
up
顾君彦 2003-10-21
  • 打赏
  • 举报
回复
XML当用字符串返回,返回后,自己解释。
happydayandday 2003-10-20
  • 打赏
  • 举报
回复
System.InvalidOperationException: 生成 XML 文档时出错。 ---> System.ArgumentException: WriteStartDocument 已编写 XML 声明。
at System.Xml.XmlTextWriter.WriteProcessingInstruction(String name, String text)
at System.Xml.XmlDeclaration.WriteTo(XmlWriter w)
at System.Xml.XmlDocument.WriteContentTo(XmlWriter xw)
at System.Xml.XmlDocument.WriteTo(XmlWriter w)
at System.Xml.Serialization.XmlSerializationWriter.WriteElement(XmlNode node, String name, String ns, Boolean any)
at System.Xml.Serialization.XmlSerializationWriter.WriteElementLiteral(XmlNode node, String name, String ns, Boolean isNullable, Boolean any)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Item(Object o)
--- 内部异常堆栈跟踪的结尾 ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
这是错误提示


happydayandday 2003-10-20
  • 打赏
  • 举报
回复
你们帮我看看,这有什么错误!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Xml;
//using System.Xml.XPath;
using System.Web.Services.Protocols;

namespace WebServiceCallXml
{
/// <summary>
/// ServiceCallXml 的摘要说明。
/// </summary>
[WebService(Namespace = "China.XiAn.DongGaoXin")]
public class ServiceCallXml : System.Web.Services.WebService
{
public ServiceCallXml()
{
//CODEGEN:该调用是 ASP.NET Web 服务设计器所必需的
InitializeComponent();

}

#region Component Designer generated code

//Web 服务设计器所必需的
private IContainer components = null;

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

// WEB 服务示例
// HelloWorld() 示例服务返回字符串 Hello World
// 若要生成,请取消注释下列行,然后保存并生成项目
// 若要测试此 Web 服务,请按 F5 键

// [WebMethod]
// public string HelloWorld()
// {
// return "Hello World";
// }

//[SoapDocumentMethodAttribute(Action="CallXml",
//RequestNamespace="China.XiAn.DongGaoXin",
// ResponseNamespace="China.XiAn.DongGaoXin")
// ]


//[return:XmlDocument]
[WebMethod]
public XmlDocument CallXml(int num)
{
XmlDocument XDoc = new XmlDocument();
XmlDeclaration XDec = XDoc.CreateXmlDeclaration("1.0",null,null);
XDoc.AppendChild(XDec);
XmlElement XPath = XDoc.CreateElement("Employees");
XDoc.AppendChild(XPath);

XmlElement XEle1 = XDoc.CreateElement("Employee");
XEle1.SetAttribute("ID","1");
XPath.AppendChild(XEle1);
XmlElement XName1 = XDoc.CreateElement("Name");
XName1.InnerText = "xdl";
XEle1.AppendChild(XName1);
XmlElement XEle2 = XDoc.CreateElement("Employee");
XEle2.SetAttribute("ID","2");
XPath.AppendChild(XEle2);
XmlElement XName2 = XDoc.CreateElement("Name");
XName2.InnerText = "wgm";
XEle2.AppendChild(XName2);
return XDoc;
}
}
}
ajex 2003-10-20
  • 打赏
  • 举报
回复
一个webmethod可以返回不同类型的对象.
xingzhiyeyu 2003-10-20
  • 打赏
  • 举报
回复
用dataset返回数据就可以了

12,163

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧