I have been reading about consuming web services with javascript and it seems every example uses an htc file to accomplish this. Does this work the same way with gadgets I tried searching the forum but no results for htc. If anyone has an example that does this I would really appreciate it! Thanks in advance!

HTC files with gadgets?
robinjam
Thank you Toddos! I added httpget to my web.config for web services so I will be using that method! Do I use the same method as the sdk except changing post to httpget and removing the soapaction It is amazing that they include post in the sdk, they must not think I am confused enough already=D About serializing the data, that definately makes sense, but will have to do a little research! Thanks again, I learned very much from it I hope:)!!
Areej
ok, it seems I am on the wrong path here:) I am not familiar with Web Services, javascript or dom so gadget development is really just a learnign experience for me because these are all things I want to learn.
To start I am just making a very simple web service which looks like this:
So if I understand correctly, in my code should look as follows
{
var url = "http://MyDomain.com/WebServices/test.asmx";
var aObjHeaders = new Array();
aObjHeaders["SOAPAction"] = "http://tempuri.org/TestString";
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("<TestString xmlns="http://tempuri.org/">");
strPostArgs.append("<test>");
strPostArgs.append("test");
strPostArgs.append("</test>");
strPostArgs.append("</TestString>");
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
CallbackFn, // Callback function
Web.Utility.Prioritizer.Priorities.Medium, // Priority
strPostArgs.toString(), // HTTP Post string
aObjHeaders ); // Array of headers
r.execute();
}
Kamii47
Virgoss
The return value will be a SOAP envelope wrapping your string. You can see this by using the ASP.NET built-in test page (hit the asmx page from a browser). Web.Network.createRequest makes an asynchronous call, which means your function CallbackFn will be called with a response object when the call finishes. That response object will contain the resulting XML (response.responseXml) which you can then parse by hand using XPaths.
The code you listed (which looks like it came out of the SDK) will work in theory. In practice you're not going to be able to make the call at all. You'll get an "Access Denied" failure because XMLPost calls are not proxied (and nobody knows when they will be). That puts you awry of the Same Origin policy, which restricts calls from a web page to other sites from the same FQDN or more specific (ie, test.example.com can call foo.test.example.com or test.example.com, but not example.com). Because of that, it's currenlty recommended that you make your web service interact via XMLGet rather than XMLPost. For an ASP.NET SOAP web service, you can turn on SOAP over HTTP-GET and use that. More people tend to prefer to use a REST-like approach instead since it's simpler to work with than SOAP over GET.
This issue has been discussed a number of times both here and on the old microsoftgadgets.com forums, so you should be able to get more info and options by searching for "XMLPost".
Damiaan
One more thing -- If you are going to stick with a SOAP web service, you need to think about your inputs and outputs. For example, a lot of people write SOAP methods that output a string, and then stuff XML into that string. I suggest you not take that approach. If you do, you'll have to pull out that string and load it into a DOM to make it useful. Instead I suggest you take advantage of .NET's ability to serialize most any object to an XML representation (there are a few that don't play well, like IDictionary, but most classes will serialize properly). Then the response will contain that XML directly in the response document, which means you can access it directly without having to go through the intermediate step of loading a string into a DOM.
I'd also caution against overuse of DataSet return values. While a DataSet with schema may be nice to use in C#, it's just going to create a lot of wasted and redundant markup that'll make things harder to parse in JScript. If you really need to return a DataSet, consider returning an array of purpose-built objects instead. .NET gives you enough control over serialization that you can use Attributes to simplify the generated XML.
For input, keep in mind that you'll have to serialize any fancy input by hand. That means you probably don't want to try accepting DataSet objects as input. I'd still recommend against using string-containing-XML inputs, since real objects are better and nicer, but whatever you choose to use will need to be serialized by you in your POST args (assuming you get this working over POST, which you won't :).
stratos13
ok, I hate to have to ask another question, but it seems I don't understand how to serialize a list to be returned.
My web service looks as follows:
<%@ WebService Language="C#" Class="photos" %>using
System;using
FlickrNet;using
System.Web;using
System.Web.Services;using
System.Web.Services.Protocols;using
System.Collections;using
System.Collections.Generic;[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public
class photos : System.Web.Services.WebService{
[WebMethod]
public List<servicephoto> GetPhotos(string id)
{
List<servicephoto> list = new List<servicephoto>();
FlickrNet.PhotoCollection test = new myflickr().test(id);
foreach (FlickrNet.Photo flickphoto in test)
{
servicephoto temp = new servicephoto(flickphoto.SquareThumbnailUrl, flickphoto.WebUrl);
list.Add(temp);
}
return list;
}
}
And the Class it is building off looks like this:
[System.Serializable()]public
class servicephoto{
private string _thumb;
private string _weburl;
public string thumb { get { return _thumb; } }
public string weburl { get { return _weburl; } }
public servicephoto(string thumb, string weburl)
{
_thumb = thumb;
_weburl = weburl;
}
public servicephoto()
{
_thumb = "test1";
_weburl = "test2";
}
}
I know it works, cause I can access the List and and display the thumbnail and the url through c#, but when I invoke the xml version is comes out as follows:
Akamba
ChanKaiShi
No, SOAP over HTTPGET requires that you encode the soap SOAP POST envelope into the URL itself. Try this or this for more info on how to encode the URL. For createRequest, switch over to type "XML" and get rid of the postargs and headers. Once you do that, you can get rid of the priority as well. The response will still be the same, though.
As for serializing, there's not a whole lot to figure out for basic usage. Let's say you want to return an int. In that case, you write your method like any C# method, with an int for a return value, and then return some number. That number will be encoded in the response XML in a certain (standard) way, and you can parse it out from your gadget as you please. The same applies to more complex objects, since they can always be broken down into simpler objects. The built-in ASP.NET user interface is invaluable for seeing the XML output of your methods, so I'd definitely use that to get an idea of what your output will look like so you can build your XPath queries.
Malmer