当我尝试从asmx webservice获得响应时,我收到了(400)错误的请求。直到现在,我能够运行用户提供的服务URL并在下拉列表中获取所有webmethods。然后,我为所选的webmethod创建一个SOAP消息。当用户单击“执行”按钮时,我尝试使用SOAP消息调用webmethod。这是c#代码:
protected void btnExecute_Click(object sender, EventArgs e)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(txtWSDL.Text));
req.ContentType = "text/xml; charset=utf-8";
req.Method = "POST";
req.Accept = "text/xml";
req.Headers.Add("SOAPAction", "http://tempuri.org/" + ddlMethods.SelectedItem.Text);
StreamWriter stm = new StreamWriter(req.GetRequestStream(), Encoding.UTF8);
stm.Write(txtFormattedSoap.Text);
stm.Flush();
stm.Close();
WebResponse resp = req.GetResponse(); //I get error in this line.
}
请告诉我在哪里/哪些地方出错或者我错过了什么。