javascript - How to call JSON methods from C# WebService from external server -
How can I use the HTML5 / JavaScript site in an ASP.NET Web service (C #)? And the Web service is not in the same site as the client, so it will be a cross-domain request.
I have a little bit of experience in web programming, and all my ASP.NET pages have a faster interface For taking HTML 5 and JS, I tried to connect to my Web service for JSSR, it was a real struggle, JSON was the answer, and information
First / Server Side < / Strong>
mywebservice.asmx
will be hosted in the next web service site, Site.com
Then address "Site.com/MYWS.asmx/JSONMethod" "[WebServices (namespace =" http: // ... ")] [System.Web.Script.Services.ScriptService] Public class MYWS {[WebMethod] [ScriptMethod (UseHttpGet = true, response format = response.jason)] Public string JSONMethod (/ * Paratip Parnanam, Paratip Parnassem 2, .. etc * /) {List & lt; Object & gt; Tempobjects = New list & lt; Object & gt; (); Tempobjects.Add (New {ID = ID, Val = Val / * More Params => ParName = "ParValue", etc. *)} Var retVal = New JavaScriptSerializer () Serialize (tempobjects.ToArray ()); Reference. Response Contact Type = "App / Jason"; Var p = ""; If (Referrer Request.Palm.AllKeys.Contains ("callback") == true) P = references. request. Mercury ["callback"]. ToString (); Reference. response. White (String.format (Culture Info. Invent Culture, "{0} ({1})", P, Rate Val)); }}
Second / Customer side
myJS.js
Comments
Post a Comment