Click here to Skip to main content
15,897,704 members

How do I display the return data in XML on my ASP page from my web service?

Richard C Bishop asked:

Open original thread
I have made a simple web service that accepts a stored procedure name and a string of data. It uses those values to create a connection to a database and executes said stored procedure that is passed the string value from the ASP page. I am trying to return the data from the stored procedure as XML back to the ASP page and display it.

I will post the code I have that is attempting to do this. I would appreciate any guidance or suggestions on what to do, thank you.

This is the VBScript I have on my ASP page that gets the name/value pairs from three input fields and sends the info via SOAP to the service.
VB
Dim soapServer, soapMessage, data

    For x = 1 To Request.Form.Count()
        fieldName = Request.Form.Key(x)
        fieldValue = Request.Form.Item(x)
        If fieldName <> "Submit" And fieldName <> "Password" Then
            data = data & fieldName & "~" & fieldValue & "|"
        End If
    Next

    'service location - Production
    soapServer = "http://intranet.domain.com:54321/DataExchangeService/DataExchangeService.svc"
     
    'message including soap envelope wrapper, to send to the service
    soapMessage = "<s:Envelope xmlns:s=" & Chr(34) & "http://schemas.xmlsoap.org/soap/envelope/" & Chr(34) & ">" & _
                        "<s:Body>" & _
                            "<DataExchange xmlns=" & Chr(34) & "http://tempuri.org/" & Chr(34) & ">" & _
                                "<storedProcedure>" & storedProcedure & "</storedProcedure>"  & _
                                "<data>" & data & "</data>" & _
                            "</DataExchange>" & _
                        "</s:Body>" & _
                    "</s:Envelope>"

    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")

    xmlhttp.open "POST", soapServer, False
    xmlhttp.setRequestHeader "Man", POST & " " & soapServer & " HTTP/1.1"
    xmlhttp.setRequestHeader "SOAPAction", "http://tempuri.org/IDataExchangeService/DataExchange"
    xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"

    'Calling the service'
    xmlhttp.send(soapMessage)

 Response.Write xmlhttp.responseText


This is the c# code in my actual service.
public class DataExchangeService : IDataExchangeService
    {
        //The code below handles the customer match checking process
        public string DataExchange(string storedProcedure, string data)
        {
            string connString = ConfigurationManager.ConnectionStrings["DataExchangeConnString"].ConnectionString;
            string returnData = "";

            SqlParameter dataParameter = new SqlParameter();
            dataParameter.Value = data;
            dataParameter.ParameterName = "@data";

            SqlConnection conn = new SqlConnection(connString);
            SqlCommand cmd = new SqlCommand(storedProcedure, conn);
            SqlDataReader reader = null;

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(dataParameter);
            
            try
            {
                conn.Open();
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    returnData = SerializeToXml(reader);
                }
                return returnData;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                reader.Close();
                conn.Close();
            }
        }//end DataExchange

        public string SerializeToXml(object value)
        {
            StringWriter writer = new StringWriter();
            XmlSerializer serializer = new XmlSerializer(value.GetType());
            serializer.Serialize(writer, value);
            return writer.ToString();
        }
    }//end dataexchangeservice
}//end namespace


Nothing errors out, it just does not display anything on the page other than the HTML that was already there.
Tags: C#, XML, ASP

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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