XMLHTTP Request to C# Webservice in Javascript passes null parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • magister pips

    #1

    XMLHTTP Request 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.Activ eXObject) {
    try {
    req = new ActiveXObject(" Msxml2.XMLHTTP" );
    }
    catch(e) {
    try {
    req = new
    ActiveXObject(" Microsoft.XMLHT TP"); }
    catch(e) {
    req = false;
    }
    }
    }
    else if(window.XmlHt tpRequest) {
    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:Enve lope xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\""
    +
    " xmlns:xsd=\"htt p://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.onreadystat echange = GetMessage;
    req.open("POST" ,"http://"+window.locati on.hostname+"/MyService/
    Service.asmx",t rue);
    req.setrequesth eader("Content-type", "text/xml");
    req.setRequestH eader("SOAPActi on","https://freedom.org/MyMethod");
    req.send(strEnv elope);



    }
    }


    here is the C# for the WebService method

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

    DataProvider dp = DataProvider.In stance();

    if(Convert.ToIn t32(poid)>0)
    {
    return dp.GetPostDetai l(Convert.ToInt 32(poid), userID);
    }
    else
    {
    return dp.GetTopicDeta il(Convert.ToIn t32(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

Working...