473,770 Members | 6,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.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

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

Aug 24 '07 #2

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

Similar topics

5
1577
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 handle the request? (i.e. how do I specify what method to call in my java servlet?) I'd appreciate any help on this.....I've only got a vaey basic
7
2504
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: ---------------------------------------------------------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head>
9
5584
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, using the same HTML/JS it always returns no data (xmlhttp.responseText is null). When I try to get headers using Mozilla or display the http status code I get some obscure exception in the javascript console that I've given up on searching for an...
1
3854
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 and send the item number to the xmlHttp and works awesome. Now I need to add an apply button next to it. so they can type in the complete number then hit apply and it does the same function. I cant get it to work with the script I have. The image...
14
10018
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> function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) {
4
8283
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 problems and this one is really getting to me... I have a page that allows you to Browse Authors. There are three drop down boxes that auto-populate via AJAX. I have a file which it calls and returns the dynamically built XML file in the boxes...
3
4018
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 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()
0
1415
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 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:
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10005
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8887
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6679
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.