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
Next
soapServer = "http://intranet.domain.com:54321/DataExchangeService/DataExchangeService.svc"
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"
xmlhttp.send(soapMessage)
Response.Write xmlhttp.responseText
This is the c# code in my actual service.
public class DataExchangeService : IDataExchangeService
{
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();
}
}
public string SerializeToXml(object value)
{
StringWriter writer = new StringWriter();
XmlSerializer serializer = new XmlSerializer(value.GetType());
serializer.Serialize(writer, value);
return writer.ToString();
}
}
}
Nothing errors out, it just does not display anything on the page other than the HTML that was already there.