Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6882429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:15:08+00:00 2026-05-27T05:15:08+00:00

I have two identical web services currently installed on the same PC for testing

  • 0

I have two identical web services currently installed on the same PC for testing purposes. A request that is received by the first service, is suposed go to the second one as well. My intention was to do this using a HttpModule. I handle the request during application.BeginRequest.

public void AsyncForwardRequest(HttpRequest request)
{
    try
    {
        // Prepare web request...
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(WSaddress);

        req.Credentials = CredentialCache.DefaultCredentials;
        req.Headers.Add("SOAPAction", request.Headers["SOAPAction"]);
        req.ContentType = request.Headers["Content-Type"];
        req.Accept = request.Headers["Accept"];
        req.Method = request.HttpMethod;

        // Send the data.
        long posStream = request.InputStream.Position;
        long len = request.InputStream.Length;
        byte[] buff = new byte[len];
        request.InputStream.Seek(0, SeekOrigin.Begin);
        if (len < int.MaxValue && request.InputStream.Read(buff, 0, (int)len) > 0)
        {
            using (Stream stm = req.GetRequestStream())
            {
                stm.Write(buff, 0, (int)len);
            }

            request.InputStream.Position = posStream;
            DebugOutputStream(request.InputStream);
            request.InputStream.Seek(0, SeekOrigin.Begin);

            IAsyncResult result = (IAsyncResult)req.BeginGetResponse(new AsyncCallback(RespCallback), req);
        }
    }
    catch (Exception ex)
    {

        App.Error2(String.Format("RequestDuplicatorModule - BeginRequest; ERROR begin request: {0}", ex.Message), ex);
    }

private static void RespCallback(IAsyncResult asynchronousResult)
{
    try
    {
        // State of request is asynchronous.
        var req = (HttpWebRequest)asynchronousResult.AsyncState;
        WebResponse resp = (HttpWebResponse)req.EndGetResponse(asynchronousResult);

        Stream responseStream = resp.GetResponseStream();
        System.IO.Stream stream = responseStream;
        Byte[] arr = new Byte[1024 * 100];
        stream.Read(arr, 0, 1024 * 100);
        if (arr.Length > 0)
        {
            string body = (new ASCIIEncoding()).GetString(arr);
            Debug.Print(body);
        }
    }
    catch (WebException ex)
    {
        App.Error2(String.Format("RequestDuplicatorModule - BeginRequest; ERROR begin request: {0}", ex.Message), ex);
    }

}

This (HttpWebResponse)req.EndGetResponse(asynchronousResult) throws an exception: 500 Internal Server Error and fails. The original request goes through fine.

request.InnerStream:
…

Does this have anything to do with the web service addresses being different? In my case they’re:
http://localhost/WS/service.asmx
http://localhost/WS_replicate/service.asmx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:15:08+00:00Added an answer on May 27, 2026 at 5:15 am

    Was able to modify the AsyncForwardRequest method so that I can actually edit the SoapEnvelope itself:

    string buffString = System.Text.UTF8Encoding.UTF8.GetString(buff);
    
    using (Stream stm = req.GetRequestStream())
    {
        bool stmIsReadable = stm.CanRead;  //false, stream is not readable, how to get
                                           //around this?
                                           //solution: read Byte Array into a String,
                                           //modify <wsa:to>, write String back into a
                                           //Buffer, write Buffer to Stream
    
        buffString = buffString.Replace("http://localhost/WS/Service.asmx", WSaddress);
    
        //write modded string to buff
        buff = System.Text.UTF8Encoding.UTF8.GetBytes(buffString);
    
        stm.Write(buff, 0, (int)buff.Length);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two identical servers. Both Win2k3. I have a web service that queues
I have two websites that have an almost identical database schema. the only difference
I have two very simple, identical UITableViews in my app that are populated with
Suppose I have two documents that are identical except the lines are shuffled. Is
I have an API that services a web-based plugin for processing email. The API
I have two web applications both on the same IIS 7 box. One application
I have two identical tables with the same number of rows but with different
I have two virtual machines with seemingly identical configuration (created from the same VM
I have two identical click events for two different elements that do not share
I have two web projects, both these projects share client-side JavaScript currently residing as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.