简体   繁体   中英

How to forward SOAP request in ASP.NET on IIS6?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM