WEB开发网
开发学院图形图像Flash How to: 使用http接收和发送简单的xml请求 阅读

How to: 使用http接收和发送简单的xml请求

 2008-10-04 11:37:36 来源:WEB开发网   
核心提示: 创建一个Silverlight项目参见 How to: 创建一个Silverlight项目.同步调用web服务 在按钮的单击事件中构造URI. string symbol = _textBox.GetAttribute("value");// The target we

创建一个Silverlight项目

参见 How to: 创建一个Silverlight项目.

同步调用web服务

在按钮的单击事件中构造URI.

string symbol = _textBox.GetAttribute("value");
// The target web service must be on the same server as this Silverlight application.
string serverUri = HtmlPage.DocumentUri.ToString();
int thisApp = serverUri.IndexOf("/Silverlight.net");
// Create the web service Url with this server as its base.
serverUri = serverUri.Substring(0, thisApp) + "/Silverlight.net.webservice/cs/WebService.asmx";
// Pass the input string to the EchoInput method in the web service.
System.Uri webServiceUri = new System.Uri(serverUri + "/EchoInput?input=" + symbol);

调用Web服务

_status.Text = String.Format("Calling {0}nr", webServiceUri.ToString());
_request = new BrowserHttpWebRequest(webServiceUri);  

处理响应.

HttpWebResponse response = (HttpWebResponse)_request.GetResponse();
// Read response
StreamReader responseReader = new StreamReader(response.GetResponseStream());
string RawResponse = responseReader.ReadToEnd();
XmlReader xr = XmlReader.Create(new StringReader(RawResponse));
// Get main element
xr.ReadToFollowing("string");
// Get following text node
xr.Read();
_result.Text = "XmlReader parsed "" + xr.Value + """;
xr.Close();
_request.Close();

Tags:How to 使用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接