locked
Retrieving data from a POST method in ASP.NET Web Service RRS feed

  • Question

  • User-1495932509 posted

    Hello,

    I am developing a web service that accept a HTTP POST request, and return back an XML Data too, please how can i do that , bellow is the sample HTTP POST Data Request

    THIS IS THE SAMPLE REQUEST DATA THAT WILL BE SENT VIA HTTP POST , AND IT IS MY DUTY TO READ THE XML AND RESPONCE BACK .

    <CustomerInformationRequest>   <RouteId>HTTPGENERICv31</RouteId> <ServiceUrl>http://test.ng/pay/direct/</Servi ceUrl>   <ServiceUsername></ServiceUsername>   <ServicePassword></ServicePassword>   <FTPUrl/>   <FTPUsername/>   <FTPPassword/> <MerchantReference>6431</MerchantRefer ence> <CustReference>88fa23dc1</CustReference>   <PaymentItemCategoryCode/>   <RequestReference/>   <TerminalId/>   <Amount>0</Amount> </CustomerInformationRequest>


    I USED THE WEB METHOD TO ACCESS THE STREAM DATA

    <WebMethod>
        Public Function payment() As String

            Dim reader As StreamReader = New StreamReader(HttpContext.Current.Request.InputStream)
            Dim requestFromPost As String = reader.ReadToEnd
            Return requestFromPost

        End Function

    PLEASE WHAT SHOULD BE THE STANDARD WAY OF HANDLING THIS ISSUE ?

    Thursday, February 2, 2017 2:05 AM

All replies

  • User475983607 posted

    As stated in your other thread with the same subject... XML serialization is handled by the ASP framework.  There is no need to serialize XML just send the object to the ASMX web method.  Take a moment to read the linked tutorials in my last post.

    https://forums.asp.net/t/2114763.aspx?Creating+web+service+that+return+xml+format+data

    Thursday, February 2, 2017 11:26 AM
  • User-1495932509 posted

    Hello Sir,

    I am very Grateful for your response

    The data sent via HTTP Post will be xml, hence the content type is text/xml.   The request message will not be in a parameter but a raw post directly to stream.

    I WANT TO READ THE stream Data . That is where i am stack.

    This is the Web Method i have tried

    <WebMethod>
        Public Function payment() As String

            Dim reader As StreamReader = New StreamReader(HttpContext.Current.Request.InputStream)
            Dim requestFromPost As String = reader.ReadToEnd
            Return requestFromPost

        End Function

    Thursday, February 2, 2017 11:33 AM
  • User475983607 posted

    I assume the following snippet is an ASMX web service?

    <WebMethod>
        Public Function payment() As String
    
            Dim reader As StreamReader = New StreamReader(HttpContext.Current.Request.InputStream)
            Dim requestFromPost As String = reader.ReadToEnd
            Return requestFromPost
    
        End Function

    ASMX is a SOAP (protocol) service.  Essentially, messages are wrapped SOAP envelop.  Your design will not work.  Please see my previous post and read through the links for more information.

    Web API might be a better option.  Again, you can find more information in my previous post.

    Are you trying to build a custom XML service?

    Thursday, February 2, 2017 1:40 PM
  • User-1495932509 posted

    Hello,

    I am sorry i may not put on my question correctly but i do receive the posted data but not in correct format

    HTML POST

     <form name="form1" action="http://localhost/prosessor.asmx/payment"  method="post">

            <input name="xml_data" type="hidden" value="<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>"  />
        </form>
        <script language="javascript">
             document.forms["form1"].submit();
        </script>

    XML DATA SENT ON HTTP POST

    <note>
      <to>Tove</to>
      <from>Jani</from>
      <heading>Reminder</heading>
      <body>Don't forget me this weekend!</body>
    </note>

    DATA RECEIVED FROM HTTP POST

    <string>xml_data=%3Cnote%3E%3Cto%3ETove%3C%2Fto%3E%3Cfrom%3EJani%3C%2Ffrom%3E%3Cheading%3EReminder%3C%2Fheading%3E%3Cbody%3EDon%27t+forget+me+this+weekend%21%0D%0A%3C%21--+Visual+Studio+Browser+Link+--%3E%0D%0A%3Cscript+type%3D</string>

    THIS IS EXACTLY WHAT I AM TRYING TO ACHIVE. I WANT TO GET THE ACTUAL XML DATA THAT WAS SENT FROM HTTP POST.

    THAnk you

    Thursday, February 2, 2017 4:19 PM
  • User475983607 posted

    You're submitting an XML string from an HTML input field.  

    The format you are seeing is call URL Encoding.  The browser URL encodes special characters when posting www-form-urlencoded content.  Simply pass the string through a url decode.

    https://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.110).aspx

    The big question is why are you using an ASMX service?    

     

    Thursday, February 2, 2017 6:45 PM