编写Web service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace SilverlightApplication10.Web
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string GetXML()
{
string s;
s = @"<body IsMember='true'>
<form_LRB>
<YYSRBQ>3536456.98</YYSRBQ>
<YYCBBQ>456798.00</YYCBBQ>
<XSFYBQ>3456.00</XSFYBQ>
<YYLRBQ>255456.32</YYLRBQ>
</form_LRB>
<head>
<createTime>2008-12-10</createTime>
<form>
<formId>ADGH4368FDG3465</formId>
<instanceId>DG2H9J-DG22HG-ASF42F-55FFG</instanceId>
</form>
</head>
<base>
<NSRMC>东莞市愉达玻璃装饰工程有限公司</NSRMC>
</base>
</body>";
return s;
}
}
}
引用代理类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightApplication10.MyXMLService;
using System.Xml;
using System.IO;
namespace SilverlightApplication10
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
GetService();
}
private void GetService()
{
WebService1SoapClient ws = new WebService1SoapClient();
ws.GetXMLCompleted += new EventHandler<GetXMLCompletedEventArgs>(ws_GetXMLCompleted);
ws.GetXMLAsync();
}
void ws_GetXMLCompleted(object sender, GetXMLCompletedEventArgs e)
{
if (e.Error == null)
{
using (XmlReader responseReader = XmlReader.Create(new StringReader(e.Result)))
{
responseReader.ReadToFollowing("YYSRBQ");
decimal YYSRBQ = responseReader.ReadElementContentAsDecimal();
responseReader.ReadToFollowing("YYCBBQ");
decimal YYCBBQ = responseReader.ReadElementContentAsDecimal();
responseReader.ReadToFollowing("YYLRBQ");
decimal YYLRBQ = responseReader.ReadElementContentAsDecimal();
responseReader.ReadToFollowing("instanceId");
string instanceId = responseReader.ReadInnerXml();
responseReader.ReadToFollowing("NSRMC");
string name = responseReader.ReadInnerXml();
OutputText.Text = "表单实例:" + instanceId + ""n" + name + ""n营业收入:" + YYSRBQ + ""n营业成本:" + YYCBBQ + ""n营业利润:" + YYLRBQ;
}
}
}
}
}