If you want the flexibility of WCF, the following code should get you started. WCF can be more complicated than the other answers, but it provides some benefits like increased flexibility and being able to host your services from a Windows Service.
Create a service that looks like:
[ServiceContract]
public interface ITestService {
[OperationContract]
[WebGet(
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Xml
)]
XElement DoWork(string myId);
}
And the implentation would be:
public class TestService : ITestService {
public XElement DoWork(string myId) {
return new XElement("results", new XAttribute("myId", myId ?? ""));
}
}
Your application config (web.config or app.config) file would contain something like the following:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="WebApplication1.TestService">
<endpoint behaviorConfiguration="WebBehavior"
binding="webHttpBinding"
contract="WebApplication1.ITestService">
</endpoint>
</service>
</services>
</system.serviceModel>
If you were to host this on an ASP.NET site, you'd have a file called TestService.svc with the following in it:
<%@ ServiceHost Language="C#" Debug="true"
Service="WebApplication1.TestService"
CodeBehind="TestService.svc.cs" %>