首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

用url访问webservice出错,

2012-03-16 
用url访问webservice出错,急!!在线等用url地址访问webservice,url地址如:http://localhost:9109/Service1.

用url访问webservice出错,急!!在线等
用url地址访问webservice,url地址如:http://localhost:9109/Service1.asmx/Test?a=123 

webservice代码:

C# code
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;        }    }}


用上述url地址直接访问报错:
因 URL 意外地以“/Test”结束,请求格式无法识别。

用后台webrequest请求也是报错
C# code
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();    }}
 


[解决办法]
ResponseFormat=ResponseFormat.Xml 我这不返回xml格式了?

热点排行