asp.net - how to call cross domain WebService/WCF in JQuery -
update1:
here getting when copy , paste service url in ie browser:
http://myservername/myservices.svc?wsdl
- <wsdl:message name="ilodge_getcountfor"> <wsdl:part name="parameters" element="tns:getcountfor" /> </wsdl:message> - <wsdl:message name="ilodge_getcountfore"> <wsdl:part name="parameters" element="tns:getcountfor" /> </wsdl:message> - <wsdl:message name="ilodge_getcountfor_input"> <wsdl:part name="parameters" element="tns:getcountfor" /> </wsdl:message> - <wsdl:message name="ilodge_getcountfor"> <wsdl:part name="parameters" element="tns:getcountfor" /> </wsdl:message>
http://myservername/myservices.svc?xsd=xsd0
- <xs:element name="getcountfor"> - <xs:complextype> - <xs:sequence> <xs:element minoccurs="0" name="getcountforresult" type="xs:long" /> </xs:sequence> </xs:complextype> </xs:element> - <xs:element name="getcountfor"> - <xs:complextype> - <xs:sequence> <xs:element minoccurs="0" name="id" nillable="true" type="xs:string" /> <xs:element minoccurs="0" name="levelid" type="xs:long" /> </xs:sequence> </xs:complextype> </xs:element> - <xs:element name="getcountfor"> - <xs:complextype> - <xs:sequence> <xs:element minoccurs="0" name="getcountfor" type="xs:long" /> </xs:sequence> </xs:complextype> </xs:element>
update:
i see services returning me xml:
public override string tostring() { //- <name>clue</name><desc>clue list</desc> stringbuilder sb = new stringbuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); sb.appendline("<kml xmlns=\"somesite">"); sb.appendline("<folder>"); sb.appendline("<name>clue</name>"); sb.appendline("<desc>clue list</desc>"); sb.appendline("</folder>"); sb.appendline("</kml>"); return sb.tostring(); }
i have tried different way execute below cross domain reference no success... doing wrong here? try debugging , put break point looks never execute
$(document).ready(function () { $.getjson("http://servername/tools/myservice.svc/mymethod/?id=1&callback=?", null, function (result) { alert("in test: " + result); debugger $("#sptext").html(result); }); or var path = "http://servername/tools/myservice.svc/mymethod?id=1&callback=?"; $.ajax({ type: "get", url: path, contenttype: "application/json; charset=utf-8", datatype: "json", async: false, success: function (response) { debugger if (response != null) { //displaydata(response); } } }); or debugger $.ajax({ url: "http://servername/tools/myservice.svc/mymethod", data: { id: "1" }, datatype: "jsonp", success: function (json, textstatus) { alert(json.d); alert(textstatus); }, error: function (xmlhttprequest, textstatus, errorthrown) { debugger } }); or $.ajax({ type: "get", cache: false, url: "http://servername/tools/myservice.svc/mymethod/id=1&callback=?", scriptcharset: "utf-8", datatype: "jsonp", data: parameters, success: function (data, textstatus) { debugger }, error: function (xmlhttprequest, textstatus, errorthrown) { debugger } }); }
i guess "response" not valid jsonp.
copy url browsers adressbar show you'll see.
here example how jsonp looks like:
somefunction({'foo':'some foo','bar':'some bar'})
a live example flickr: http://www.flickr.com/services/rest/?method=flickr.test.echo&format=json&api_key=08e4f6fc4216b1216c5f521133ecbd9b&jsoncallback=functionname
it looks call of function object-literal argument. looks that, because later function-call. way jsonp works is: <script>
-element injected dom , has set provided url src-attribute. ressource not string or xml-document, it's javascript-file. if embedded document executed , argument accessible.
i can't tell ultimate way create jsonp, depends on data , it(and of course on given environment too).
Comments
Post a Comment