读书人

在winform中怎么才能把一个生成好的XM

发布时间: 2012-01-10 21:26:51 作者: rapoo

在winform中如何才能把一个生成好的XML文件传给web service进行解析?
我的代码:
winform.cs:其中GetWeb就是引用的一个web service

private void button1_Click(object sender, EventArgs e)
{
string xmlpath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "datatrans.xml ";

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlpath);

GetWeb.Service myweb = new GetWeb.Service();
string ss=myweb.getxml(xmlDoc);
lblName.Text = ss;


}

xml.asmx:
......
public Service () {

//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}

[WebMethod]
public string getxml(XmlDocument xmlg)
{
......
}
......

现在的问题是,在函数getxml中参数引用是否有问题?如果没有,那下面的解析应该怎么做呢?如果有问题,应该如何修改?

我现在怎么试都不行,唉,郁闷死了,哪位高人帮帮忙啊,谢谢

[解决办法]
XmlDocument 不能序列化。可以使用可序列化的对象做参数来实现WebService的访问。
[解决办法]
给你个例子试试:
[WebMethod]
public string getxml(System.Xml.XmlDocument xmlg)
{
return xmlg.DocumentElement.Attributes[0].Name.ToString();
}

winForm中调用的时候:
string xmlpath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "datatrans.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlpath);
GetWeb.Service myweb = new GetWeb.Service();
string ss = myweb.getxml((System.Xml.XmlDocument)xmlDoc);
lblName.Text = ss;

读书人网 >C#

热点推荐