Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

XMLHTTP call in Javascript to C# Webservice passes null parameters

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
magister pips - 24 Aug 2007 17:42 GMT
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
Nathaniel Greene - 24 Aug 2007 21:18 GMT
I would run a packet sniffer or a Soap message tracing tool to see what's
actually being sent. You should also be able to invoke the WebService using
an HTTP Get request without having to go through all the hoops and hollers
required for SOAP. just fyi.

> Hello, I have encountered some strange behaviour when using the
> XMLHTTP Request object in Javascript to return xml from a C#
[quoted text clipped - 81 lines]
> Thanks,
> Matt

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.