如何在 IIS6 上的 ASP.NET 中转发 SOAP 请求?

发布于 2024-12-15 06:39:00 字数 754 浏览 0 评论 0原文

我正在尝试创建一个托管在 IIS 6 上的应用程序(或 Web 服务),该应用程序将使用修改后的凭据将 SOAP 请求转发到另一个 Web 服务应用程序。

现在,我的应用程序的 Page_Load 中有类似的内容:

HttpWebRequest newRequest = (HttpWebRequest)WebRequest.Create(newUrl);
newRequest.ContentType = original.ContentType;
newRequest.ContentLength = original.ContentLength;
newRequest.Method = original.HttpMethod;
newRequest.UserAgent = original.UserAgent;
newRequest.Credentials = new NetworkCredential("login","password","domain");
HttpWebResponse response = (HttpWebResponse)newRequest.GetResponse();

问题是它在最后一行崩溃,因为 ContentLength > 。 0 并且我没有打开RequestStream,因为我不知道如何从原始请求中获取它。

我没有将这个问题命名为“如何从 HttpWebRequest 获取 SOAP 请求”,因为我相信对于我正在尝试做的事情有一个更简单的解决方案。也许是某种像 Java 中的请求调度程序。

任何帮助将不胜感激。

I'm trying to make an application (or webservice) hosted on IIS 6 that would forward SOAP requests to another web services application using modified credentials.

For now I have something like this in Page_Load of my app:

HttpWebRequest newRequest = (HttpWebRequest)WebRequest.Create(newUrl);
newRequest.ContentType = original.ContentType;
newRequest.ContentLength = original.ContentLength;
newRequest.Method = original.HttpMethod;
newRequest.UserAgent = original.UserAgent;
newRequest.Credentials = new NetworkCredential("login","password","domain");
HttpWebResponse response = (HttpWebResponse)newRequest.GetResponse();

The problem is it crashes on the last line because the ContentLength is > 0 and I don't open RequestStream, because I don't know how to get it from the oryginal request.

I didn't title this question "How to get SOAP Request from HttpWebRequest" because I believe there is an easier solution to what I'm trying to do. Maybe some kind of request dispacher like in Java.

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不甘平庸 2024-12-22 06:39:00

SOAP 请求没有什么神奇之处——毕竟它只是 HTTP。您应该能够使用如下方式复制请求正文:

Context.Request.InputStream.CopyTo(newRequest.GetRequestStream());

此外,您还应该确保复制原始请求中可能设置的所有其他重要 HTTP 标头。

There is nothing magic about a SOAP request - it is just HTTP after all. You should be able to copy the request body using something like this:

Context.Request.InputStream.CopyTo(newRequest.GetRequestStream());

Also you should make sure you copy all the other significant HTTP headers that might be set in the original request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文