Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Why don't you migrate your ASMX webservice to WCF?</strong></p> <p>The WCF API in .NET Framework 3.5 supports JSON web services natively.</p> <p>In addition Microsoft declared ASMX as "legacy technology", and suggests "Web services and XML Web service clients should now be created using Windows Communication Foundation (WCF)". (<a href="http://msdn.microsoft.com/en-us/library/bb552872.aspx" rel="nofollow noreferrer">Source</a>).</p> <p>You may want to check out these links to get started:</p> <ul> <li><a href="http://dotnetslackers.com/articles/ajax/json-enabledwcfservicesinaspnet35.aspx" rel="nofollow noreferrer">JSON-Enabled WCF Services in ASP.NET 3.5</a></li> <li><a href="http://dotnetninja.wordpress.com/2008/05/02/rest-service-with-wcf-and-json/" rel="nofollow noreferrer">REST Service with WCF and JSON</a></li> <li><a href="http://dotnetslackers.com/articles/ajax/json-enabledwcfservicesinaspnet35.aspx" rel="nofollow noreferrer">Creating a JSON Service with WebGet and WCF 3.5</a></li> <li><a href="http://www.asp.net/downloads/starter-kits/wcf-rest/" rel="nofollow noreferrer">Microsoft WCF REST Starter Kit</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/bb332338.aspx" rel="nofollow noreferrer">Hosting and Consuming WCF Services</a></li> </ul> <p>In addition, you may also want to read through the following example which I "extracted" from a self-hosted WCF project of mine. Self-hosted WCF services do not require IIS, but can be served from any managed .NET application. This example is being hosted in a very simple <em>C# Console Application</em>:</p> <p><strong>IContract.cs</strong></p> <pre><code>using System; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; namespace MyFirstWCF { [ServiceContract] public interface IContract { [OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/CustomerName/{CustomerID}")] string GET_CustomerName(string CustomerID); } } </code></pre> <p><strong>Service.cs</strong></p> <pre><code>using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Syndication; using System.ServiceModel.Web; namespace MyFirstWCF { [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.NotAllowed)] public class Service : IContract { public string GET_CustomerName(string CustomerID) { return "Customer Name: " + CustomerID; } } } </code></pre> <p><strong>WCFHost.cs</strong> (Console Application)</p> <pre><code>using System; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Web; using System.ServiceModel.Description; using System.Threading; using System.Text; namespace MyFirstWCF { class Program { private static WebServiceHost M_HostWeb = null; static void Main(string[] args) { M_HostWeb = new WebServiceHost(typeof(MyFirstWCF.Service)); M_HostWeb.Open(); Console.WriteLine("HOST OPEN"); Console.ReadKey(); M_HostWeb.Close(); } } } </code></pre> <p><strong>app.config</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="MyFirstWCF.Service"&gt; &lt;endpoint address="http://127.0.0.1:8000/api" binding="webHttpBinding" contract="MyFirstWCF.IContract" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;/system.serviceModel&gt; &lt;/configuration&gt; </code></pre> <p>The above example is very basic. If you build a request with <a href="http://www.fiddler2.com/" rel="nofollow noreferrer">Fiddler</a> to <code>http://127.0.0.1:8000/api/CustomerName/1000</code> it will simply return <code>"Customer Name: 1000"</code>.</p> <p>Make sure to set the <code>content-type: application/json</code> in the request header. To return more complex data structures, you will have to use Data Contracts. These are constructed as follows:</p> <pre><code>[DataContract] public class POSITION { [DataMember] public int AssetID { get; set; } [DataMember] public decimal Latitude { get; set; } [DataMember] public decimal Longitude { get; set; } } </code></pre> <p>You need to add .NET References to <code>System.RuntimeSerialization</code>, <code>System.ServiceModel</code> and <code>System.ServiceModel.Web</code> for this example project to compile.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload