Click here to Skip to main content
13,249,401 members (30,596 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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.
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
    'service location - Production
    soapServer = ""
    'message including soap envelope wrapper, to send to the service
    soapMessage = "<s:Envelope xmlns:s=" & Chr(34) & "" & Chr(34) & ">" & _
                        "<s:Body>" & _
                            "<DataExchange xmlns=" & Chr(34) & "" & Chr(34) & ">" & _
                                "<storedProcedure>" & storedProcedure & "</storedProcedure>"  & _
                                "<data>" & data & "</data>" & _
                            "</DataExchange>" & _
                        "</s:Body>" & _
    Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") "POST", soapServer, False
    xmlhttp.setRequestHeader "Man", POST & " " & soapServer & " HTTP/1.1"
    xmlhttp.setRequestHeader "SOAPAction", ""
    xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    'Calling the service'
 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;
                reader = cmd.ExecuteReader();
                while (reader.Read())
                    returnData = SerializeToXml(reader);
                return returnData;
            catch (Exception)
        }//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.
Posted 13-Dec-12 6:23am
Updated 13-Dec-12 8:00am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I figured out my problem. I was not creating a DOM Document in my VBScript to hold my xml response. Also, my serializing of my data from the stored procedure needed some tweaking too.

Here is what I added:

This is my VBScript.
Set objXMLDoc = Server.createobject("MSXML2.DOMDocument")
objXmlDoc.async = false

This is my code-behind.
DataTable dataTable = new DataTable();
dataTable.TableName = "ReturnData";
dataTable.WriteXml(xmlWriter, XmlWriteMode.WriteSchema, false);
Tarun Y Mangukiya 18-Dec-12 2:18am
I think that DOM is correct solution. I am using...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You would do better to write web pages that work in browsers other than IE. You could also then use Chrome to debug your code. You can also add MsgBoxes to your script to view the return from your function call, to see what is coming back.
richcb 13-Dec-12 17:58pm
That is a good point. So are you saying that the VBScript would not work in Chrome? I have the service code published to a test server and could access my ASP page in any browser. How do I go about debugging in the Chrome browser?
Christian Graus 13-Dec-12 18:00pm
Wow - you got this far and didn't know that ? Yes, VBScript is IE only. You should be testing in Chrome NOW, and so should know this. In Chrome, if you right click on an element and choose 'Inspect Element', a debugger opens where you can set breakpoints in script, etc
richcb 13-Dec-12 18:07pm
Well this is my first time ever using VBScript so I still have a lot to learn. Thank you for the info.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100