Google Groups Home
Help | Sign in
XMLHTTP Call to C# Webservice in Javascript passes null parameters
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
magister pips  
View profile
 More options Aug 24 2007, 12:46 pm
Newsgroups: microsoft.public.xml.soapsdk
From: magister pips <mbas...@gmail.com>
Date: Fri, 24 Aug 2007 09:46:38 -0700
Local: Fri, Aug 24 2007 12:46 pm
Subject: XMLHTTP Call to C# Webservice in Javascript passes null parameters
Hello, I have encountered some strange behaviour when using the
XMLHTTP Request object in Javascript to return xml from a C#
Webservice Method.  I create a SOAP envelope and send it off to the
Webservice, which I have debug points in, which when hit I can see
that all the parameters are coming thru as null.  I can't figure out
why this is, any experts out there would be a great help.

Here is my Javascript:

function showMsga()
{
if(window.ActiveXObject) {
        try {
                req = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
                try {
                        req = new
ActiveXObject("Microsoft.XMLHTTP");                 }
                catch(e) {
                        req = false;
                }
        }

}

else if(window.XmlHttpRequest) {
        try {
        req = new XmlHttpRequest();
        }
        catch(e) {
        req = false;
        }

}

var wer = window.location;

if(req) {
        var strEnvelope = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
\n"+
        "<soap:Envelope xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\""
+
        " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
+
        " xmlns:soap= \"http://schemas.xmlsoap.org/soap/envelope/\">
\n" +
        "<soap:Body>\n" +
        "<MyMethod xmlns=\"https://freedom.org/MyService\">\n" +
                "<tpid xsi:type=\"xsd:string\">3083</tpid>\n" +
                "<poid xsi:type=\"xsd:string\">1045</poid>\n" +
        "</MyMethod>" + "</soap:Body>" + "</soap:Envelope>";

req.onreadystatechange = GetMessage;
req.open("POST","http://"+window.location.hostname+"/MyService/
Service.asmx",true);
req.setrequestheader("Content-type", "text/xml");
req.setRequestHeader("SOAPAction","https://freedom.org/MyMethod");
req.send(strEnvelope);

}
}

here is the C# for the WebService method

[WebMethod]
public string MyMethod(string tpid, string poid)
{
int userID = Users2.GetUserID();

DataProvider dp = DataProvider.Instance();

if(Convert.ToInt32(poid)>0)
{
        return dp.GetPostDetail(Convert.ToInt32(poid), userID);

}

else
{
        return dp.GetTopicDetail(Convert.ToInt32(tpid), userID);

}
}

originally the method took integers but I switched them to strings in
the hope they would work,
any and all comments and hints are greatly appreciated.

Thanks,
Matt


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google