用url访问webservice出错,急!!在线等
用url地址访问webservice,url地址如:http://localhost:9109/Service1.asmx/Test?a=123
webservice代码:
using System;using System.Collections.Generic;using System.Web;using System.Web.Services;namespace WebService1{ /// <summary> /// Service1 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] public class Service1 : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public string Test(string a) { return a; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Net;using System.IO;public partial class Default12 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { string url = "http://localhost:9109/Service1.asmx/Test?a=123"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream()); string ret = sr.ReadToEnd(); Response.Write(ret); Response.End(); }}