[ServiceContract(Namespace = "http//Redwood.NGT.BES")]
public interface IBillingEnquiryStub
{
[OperationContract]
string GetData(int value);
}
public class BESStubService : IBillingEnquiryStub
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
class Program
{
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:1325/RedwoodNGTBES/Service");
ServiceHost selfHost = new ServiceHost(typeof(BESStubService), baseAddress);
try
{
// Step 3 of the hosting procedure: Add a service endpoint.
selfHost.AddServiceEndpoint(
typeof(IBillingEnquiryStub),
new WSHttpBinding(),
"BESStubService");
// Step 4 of the hosting procedure: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 of the hosting procedure: Start (and then stop) the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press to terminate service.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown the service.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("An exception occurred: {0}", ce.Message);
selfHost.Abort();
}
}
}
|