我需要将保留类型对象从一个主域传递到子域,其中是安装了 ssl 的页面。所以有必要在那里发送所有值并在那里消费/
我厌倦了使用以下方法创建 Web 服务
[WebMethod]
public List<Reservation> getReservation()
{
if (HttpContext.Current.Session["reservation"] != null)
{
return (List<Reservation>)HttpContext.Current.Session["reservation"];
}
else
{
List<Reservation> objres = new List<Reservation>();
return objres;
}
}
所以我可以在子域页面中使用该 Web 服务
以下代码写在启用 ssl 的页面上
string FullUrl = "http://localhost/goldlinetravel/webservice.asmx/getReservation";
HttpWebRequest request = WebRequest.Create(FullUrl.ToString()) as HttpWebRequest;
request.ContentType = "text/xml; charset=UTF-8";
request.Accept = "application / xml";
request.Method = "POST";
request.ContentLength = 0;
DataSet dsReservation = new DataSet();
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
response.GetResponseStream();
dsReservation.ReadXml(response.GetResponseStream());
}
它抛出错误 500 服务器错误。
Web服务中还有另一种方法
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
当我使用以下代码使用此 Web 服务时,没有错误
string FullUrl = "http://localhost/goldlinetravel/webservice.asmx/HelloWorld";
HttpWebRequest request = WebRequest.Create(FullUrl.ToString()) as HttpWebRequest;
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "application / xml";
request.Method = "POST";
request.ContentLength = 0;
DataSet dsReservation = new DataSet();
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
response.GetResponseStream();
dsReservation.ReadXml(response.GetResponseStream());
}
我的 getReservation 方法没有发现什么问题