Hi,
I am writing a gadget in which i am making a web network request to a web service
i have written the code from thje examples given in SDK.
Here is the sample
function
GetData(int id){
window.alert(
"It is Called");// In the code below, we are calling a web service with the following function prototype: // public TrackingResponse GetTrackingInfo(string trackingNumber) var url = "http://localhost/GetDataService/Service.asmx"; var aObjHeaders = new Array();aObjHeaders[
"SOAPAction"] = http://tempuri.org/GetDetails;aObjHeaders[
"Content-Type"] = "text/xml"; var strPostArgs = new Web.StringBuilder();strPostArgs.append(
"< xml version=\"1.0\" encoding=\"utf-8\" >");strPostArgs.append(
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");strPostArgs.append(
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");strPostArgs.append(
"<soap:Body>");strPostArgs.append(
"<GetDetails xmlns=\"http://tempuri.org\">");strPostArgs.append(
"<id>");strPostArgs.append(
"id.toString()");strPostArgs.append(
"</id>");strPostArgs.append(
"</GetDetails>");strPostArgs.append(
"</soap:Body>");strPostArgs.append(
"</soap:Envelope>");window.alert(strPostArgs.toString());
var r = Web.Network.createRequest( Web.Network.Type.XMLPost,url,null,responsedata,Web.Utility.Prioritizer.Priorities.Medium,strPostArgs.toString(),aObjHeaders ); // Array of headersr.execute();
}
function
responsedata(response){
window.alert(response.status.toString());
}
Here i have observed that the parameter that i am passing to web method is not getting passed to the service.But the response is coming from the service
please help me in solving it.
regards
krishna

passing parameters to a web service in soap request from Web.network.Create Request
Hooper
I have found my mistake:
was:
strPostArgs.append("<GetSpaceStat xmlns=\"http://tempuri.org\">");
necessary:
strPostArgs.append("<GetSpaceStat xmlns=\"http://tempuri.org/\">");
nikos z
Hi mmsignh,
I'm still having the problem, I created a simple web service at:
http://margell.net/casey/service.asmx
That has a single Hello operation. Feel free to play with this service a bit. For a given name it returns "Hello NAME!".
I'm having the same problem as before where I don't ever see my output after the execute statement and the callback never gets called. Here is the exact code I'm running right now:
var url = "http://margell.net/casey/service.asmx";
var aObjHeaders = new Array();
aObjHeaders["SOAPAction"] = "CaseyM.Service/Hello";
aObjHeaders["Content-Type"] = "text/xml";
var strPostArgs = new Web.StringBuilder();
strPostArgs.append("< xml version=\"1.0\" encoding=\"utf-8\" >");
strPostArgs.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
strPostArgs.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlnsoap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
strPostArgs.append("<soap:Body>");
strPostArgs.append("<Hello xmlns=\"CaseyM.Service\">");
strPostArgs.append("<name");
strPostArgs.append("Casey");
strPostArgs.append("</name>");
strPostArgs.append("</Hello>");
strPostArgs.append("</soap:Body>");
strPostArgs.append("</soap:Envelope>");
var r = Web.Network.createRequest( Web.Network.Type.XMLPost, // Network type
url, // URL of web service
null, // Object passed to callback
serviceCallback, // Callback function
Web.Utility.Prioritizer.Priorities.Medium, // Priority
strPostArgs.toString(), // HTTP Post string
aObjHeaders ); // Array of headers
alert("finished building string, calling execute");
r.execute();
alert("leaving getImageFilename");
}
function serviceCallback(response) {
alert("in serviceCallback, response: \n" + response);
}
EDITED:
Here is the code for the service:
<%@ WebService Language="C#" Class="Service" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace="CaseyM.Service",
Description="<b>A simple test web service.</b>")]
public class Service : System.Web.Services.WebService
{
public Service() { }
[WebMethod]
public string Hello(string name) {
return "Hello " + name + "!";
}
}
AE_Cory
I found my problem as well. The issue was that IE was blocking cross domain calls. Argh.
Jassim Rahma
The parameters are not getting passed because XMLPost doesn't work. Web.Network.createRequest uses a proxy system to allow cross-domain calls that would otherwise be blocked by the Same Origin Policy. Unfortunately, last I checked that proxy does not like XMLPost. It seems that things may have changed somewhat, as it used to be that XMLPost just wouldn't go through the proxy at all and you'd end up with an Access Denied error. Now it looks like it's going through, but stripping off all of the POST data, making the type just as useless for a different reason.
It's been a while since I tried XMLPost. I may have to try it again to see if it may actually work now.
PostMeridian
seems, your problem in
strPostArgs.append("id.toString");
necessary
strPostArgs.append(id.toString);
but I have same problem - not passing parameter
var m_spacesName =
"http://live.com"; var aObjHeaders = new Array();aObjHeaders[
"SOAPAction"] = "http://tempuri.org/SpaceStat";aObjHeaders[
"Content-Type"] = "text/xml"; var strPostArgs = new Web.StringBuilder();strPostArgs.append(
"< xml version=\"1.0\" encoding=\"utf-8\" >");strPostArgs.append(
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");strPostArgs.append(
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlnsstrPostArgs.append(
"<soap:Body>");strPostArgs.append(
"<SpaceStat xmlns=\"http://tempuri.org\">");strPostArgs.append(
"<host>");strPostArgs.append(m_spacesName);
strPostArgs.append(
"</host>");strPostArgs.append(
"</SpaceStat>");strPostArgs.append(
"</soap:Body>");strPostArgs.append(
"</soap:Envelope>"); var r = Web.Network.createRequest( Web.Network.Type.XMLPost, // Network typeurl,
// URL of web service null, // Object passed to callbackCallbackFn,
// Callback functionWeb.Utility.Prioritizer.Priorities.Medium,
// PrioritystrPostArgs.toString(),
// HTTP Post stringaObjHeaders );
// Array of headersr.execute();
passing null instead of m_spacesName value. Why
ShortNSweet
on http://microsoftgadgets.com/livesdk/docs/ApiRef.Web.Network.htm exists example, like my. What proxy is necessaryMichaS
Hi Casey,
There seem to be some config errors on your server as when i try to access the .asmx file, i get an error :
Server Error in '/' Application.
stefaan_meeuws
Hi mmsignh,
Would it be possible for you to post the code that you got to work when consuming a web service
I've based my code on the example from the SDK (http://microsoftgadgets.com/livesdk/docs/ApiRef.Web.Network.htm) but when I execute the request I'm not getting any error but at the same time I'm not getting the alert after calling execute or the alert in the callback. Here's a snippet from my code, I've bolded the areas that I changed for anonymity's sake:
function getImageFilename() {
alert("entering getImageFilename");
var aObjHeaders = new Array();
aObjHeaders["SOAPAction"] = "namespace.Service/GetFilename";
aObjHeaders["Content-Type"] = "text/xml; charset=utf-8";
//aObjHeaders["Host"] = "domain";
alert("getImageFilename: 1")
var strPostArgs = new Web.StringBuilder();
alert("getImageFilename: 2")
strPostArgs.append("< xml version=\"1.0\" encoding=\"utf-8\" >");
strPostArgs.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
strPostArgs.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns
strPostArgs.append("<soap:Body>");
strPostArgs.append("<GetFilename xmlns=\"domain\">");
strPostArgs.append("<email>");
strPostArgs.append(m_savedPreferences[EMAIL]);
strPostArgs.append("</email>");
strPostArgs.append("</GetFilename>");
strPostArgs.append("</soap:Body>");
strPostArgs.append("</soap:Envelope>");
alert("getImageFilename: 3")
var r = Web.Network.createRequest(Web.Network.Type.XMLPost, // Network type
WEBSERVICEURL, // URL of web service
null, // Object passed to callback
serviceCallback, // Callback function
Web.Utility.Prioritizer.Priorities.Medium, // Priority
strPostArgs.toString(), // HTTP Post string
aObjHeaders ); // Array of headers
alert("finished building string, calling execute");
r.execute();
alert("leaving getImageFilename");
}
function serviceCallback(response) {
alert("in serviceCallback, response: \n" + response);
}
Any input anyone has is greatly appreciated.
Casey
sqlexpressbeginner
Hi Casey
Pasted below is the code that worked perfectly fine for me.
var url = http://{URL TO SERVICE.asmx file};
var aObjHeaders = new Array();
aObjHeaders["SOAPAction"] = "{SERVICE NAME}/{METHOD NAME}";
aObjHeaders["Content-Type"] = "text/xml";
var strPostArgs = new Web.StringBuilder();
strPostArgs.append("< xml version=\"1.0\" encoding=\"utf-8\" >");
strPostArgs.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
strPostArgs.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns
oap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
strPostArgs.append("<soap:Body>");
strPostArgs.append("<{METHOD NAME} xmlns=\"{SERVICE NAME}\">");
strPostArgs.append("<{PARAMETER NAME}>");
strPostArgs.append({VALUE OF PARAMETER});
strPostArgs.append("</{PARAMETER NAME}>");
strPostArgs.append("</{METHOD NAME}>");
strPostArgs.append("</soap:Body>");
strPostArgs.append("</soap:Envelope>");
var r = Web.Network.createRequest( Web.Network.Type.XMLPost, // Network type
url, // URL of web service
null, // Object passed to callback
OnFeedReceived, // Callback function
Web.Utility.Prioritizer.Priorities.Medium, // Priority
strPostArgs.toString(), // HTTP Post string
aObjHeaders ); // Array of headers
r.execute();
Just replace the parameters marked above in {.....} with actual values and it should work fine for you. Let me know if you still see problems.
ThanksXi0N
Hi all,
I just went ahead and tried submitting an XMLPost request to my web service through a Live Gadget and it worked !! So, it seems the days of XMLPost not working are actually over.
I just took the code sample from the Live Gadget API reference and replaced the sample service and sample method name with the names of my service and method and it worked like a charm.
Thanks