Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi Guys

Before you answer read! and please dont give me a result you quickly Googled, i need someone who actualy dealt with this and can give me an actual answer.

I have a delphi program that calls my .net web service, problem is the parameters always comes through as a null value , all i need is to pasre a simple string through so I built a bit of code into my Global.asax code.

C#
protected void Application_BeginRequest(object sender, EventArgs e)
        {
            string name = HttpContext.Current.Request.Url.ToString();
            if (name.Contains("PMA/PMAService.asmx"))
            {
                // Create byte array to hold request bytes
                byte[] inputStream = new byte[HttpContext.Current.Request.ContentLength];

                // Read entire request inputstream
                HttpContext.Current.Request.InputStream.Read(inputStream, 0, inputStream.Length);

                //Set stream back to beginning
                HttpContext.Current.Request.InputStream.Position = 0;
                
                //Get  XML request
                string requestString =UTF8Encoding.UTF8.GetString(inputStream);
    
            }
            
        }


This captures the incoming soap requests

From delphi the request is as follow:
XML
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<saySomething xmlns="http://tempuri.org/"><xsd:data>hello</xsd:data></saySomething>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


I need to change this into Following (this is what comes from a .net client program):

XML
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<saySomething xmlns="http://tempuri.org/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><data>hello</data></saySomething>
</s:Body>
</s:Envelope>

I know how to manipulate the string but how do i manipulate the request input stream before it hits the web service and runs the command and returns the result ?

Thank you in advance
Posted

1 solution

found a solution.

It involves inherriting from the SoapExtension and changing data in the

public override void ProcessMessage()

Method in order to rewrite the stream beforeit becomes deserialized.

Will write an article regarding this over the weekend.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900