当前位置: 代码迷 >> Web Service >> 用url访问webservice出错,
  详细解决方案

用url访问webservice出错,

热度:334   发布时间:2016-05-02 02:58:02.0
用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格式了?
  相关解决方案