(400) 动态调用 asmx webmethod 时出现错误请求
当我尝试从 asmx Web 服务获取响应时,收到 (400) 错误请求。到目前为止,我可以运行用户提供的服务 URL 并在下拉列表中获取所有 Web 方法。然后,我为选定的 Web 方法创建 SOAP 消息。当用户单击“执行”按钮时,我尝试使用 SOAP 消息调用 Web 方法。这是 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.
}
请让我知道哪里/哪里做错了或者我是否遗漏了某些内容。
I am getting (400) bad request when I try to get response from the asmx webservice. Till now, I am able to run the service url provided by the user and get all the webmethods in a dropdown. I then create a SOAP message for the selected webmethod. When user clicks Execute button, I am trying to call the webmethod with SOAP message. Here is the c# code:
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.
}
Please let me know where/what am doing wrong or if I am missing something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论