Skip to content

Instantly share code, notes, and snippets.

@smonn
Last active December 18, 2015 16:39
Who said WCF (svc) requires more configuration than a web service (asmx)? When it comes to hosting a simple web service which only purpose is to communicate through Ajax and JSON, this is enough. And no, nothing (related to WCF configuration) needs to be put in the web.config. See http://msdn.microsoft.com/en-us/library/bb472534(v=vs.90).aspx fo…

Who said WCF (svc) requires more configuration than a web service (asmx)? When it comes to hosting a simple web service which only purpose is to communicate through Ajax and JSON, this is enough. And no, nothing (related to WCF configuration) needs to be put in the web.config. See MSDN for more details about configuration-less WCF.

using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
namespace Namespace
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class HelloService
{
[OperationContract]
[WebInvoke(Method = "POST")]
public string Hello(string name)
{
return string.Format("Hello {0}!", name);
}
}
}
<%@ ServiceHost Language="C#" Debug="true" Service="Namespace.HelloService" CodeBehind="HelloService.svc.cs" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment