how to generate web service out of wsdl

There isn’t a magic bullet solution for what you’re looking for, unfortunately. Here’s what you can do: create an Interface class using this command in the Visual Studio Command Prompt window: wsdl.exe yourFile.wsdl /l:CS /serverInterface Use VB or CS for your language of choice. This will create a new .cs or .vb file. Create a … Read more

Asmx web service how to return JSON and not XML?

There’s no need to create the JSON string yourself. Return the List<TrainingMasterDataStruct> and let .NET serialise it for you on the fly: [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<TrainingMasterDataStruct> getDataFromTrainingMaster() { List<TrainingMasterDataStruct> list = doStuff(); return list; } Secondly, the non-static method signatures suggest this is an asmx file (page methods are static). By default these … Read more

Capturing SOAP requests to an ASP.NET ASMX web service

You can also implement by placing the code in Global.asax.cs protected void Application_BeginRequest(object sender, EventArgs e) { // Create byte array to hold request bytes byte[] inputStream = new byte[HttpContext.Current.Request.ContentLength]; // Read entire request inputstream HttpContext.Current.Request.InputStream.Read(inputStream, 0, inputStream.Length); //Set stream back to beginning HttpContext.Current.Request.InputStream.Position = 0; //Get XML request string requestString = ASCIIEncoding.ASCII.GetString(inputStream); } I … Read more

ASMX Web Service slow first request

The delay that is experienced when a client is calling a webservice for the first time is caused by the fact that by default a XmlSerializers dll for the webservice needs to be compiled. This is causing the 2-4 seconds for the initial call. Of course this is the case when the webservice application is … Read more

Return JSON from ASMX web service, without XML wrapper?

Use this: var JsonString = ….; $.ajax({ type: “POST”, contentType: “application/json; charset=utf-8”, url: “YourWebServiceName.asmx/yourmethodname”, data: “{‘TheData’:'” + JsonString + “‘}”, dataType: “json”, success: function (msg) { var data = msg.hasOwnProperty(“d”) ? msg.d : msg; OnSucessCallBack(data); }, error: function (xhr, status, error) { alert(xhr.statusText); } }); function OnSuccessCallData(DataFromServer) { // your handler for success } and … Read more

How to get JSON response from a 3.5 asmx web service

I faced the same issue, and included the below code to get it work. [WebMethod] [ScriptMethod(UseHttpGet=true ,ResponseFormat = ResponseFormat.Json)] public void HelloWorld() { Context.Response.Clear(); Context.Response.ContentType = “application/json”; Context.Response.Write(“Hello World”); //return “Hello World”; } Update: To get a pure json format, you can use javascript serializer like below. public class WebService1 : System.Web.Services.WebService { [WebMethod] [ScriptMethod(UseHttpGet=true … Read more

Calling ASMX from jQuery

One thing that stands out is you have UseHttpGet=true but in your jQuery code you are using POST. Also here is a test page I created calling an ASMX page. [WebMethod] public Catalog[] GetCatalog() { Catalog[] catalog = new Catalog[1]; Catalog cat = new Catalog(); cat.Author = “Jim”; cat.BookName =”His Book”; catalog.SetValue(cat, 0); return catalog; … Read more