473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

XMLHTTP call in Javascript to C# Webservice 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

Aug 24 '07 #1
1 3214
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.

"magister pips" wrote:
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

Aug 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: bboyle18 | last post by:
Hi, I've been looking into the possibility of using XMLHTTP for my enterprise application but I still have a question. When you send the request to the server, how does the server know how to...
7
by: Fabri | last post by:
I'm trying to develop a way to include static files in htm pages with javascript. I'm trying to use XMLHTTP object this way: ...
9
by: fochie | last post by:
Greetings, I'm having a problem when I try to GET a file from my server via xmlhttp when using Mozilla. With IE I can get any type of file fine, get/display headers fine, etc. With Mozilla,...
1
by: wkerplunk | last post by:
Below is what I have build with several different languages. It works great but I need help, I am stuck. When you click on an item in the dropdown autocomplete div it does a mousedown function...
14
by: FMDeveloper | last post by:
Currently transitioning from a shared host to a dedicated server. The same code that works on the old server is not working on the dedicated server. It is a simple AJAX request like: <code>...
4
by: sirjohnofthewest | last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man. Hi guys, I frequently visit this site to get answers to my...
3
by: magister pips | last post by:
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...
0
by: magister pips | last post by:
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.