Service
using System.ServiceModel
ServiceContract
OperationContract
app.config
<configuration> <system.serviceModel> <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true--> <behaviors> <serviceBehaviors> <behavior name="behavior0"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> <services> <!-- TODO: The name attribute should be the fully-qualified name of the service class. --> <service name="Microsoft.Samples.GettingStarted.CalculatorService" behaviorConfiguration="behavior0" > <endpoint address="http://localhost/ServiceModelSamples/CalculatorService" binding="basicHttpBinding" contract="Microsoft.Samples.GettingStarted.ICalculator" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://localhost/ServiceModelSamples/CalculatorService" /> </baseAddresses> </host> </service> </services> </system.serviceModel> </configuration>
Program.cs
using System.ServiceModel; . . . public static void Main() { /* TODO: Replace Microsoft.Samples.GettingStarted.CalculatorService with your service class */ using (var serviceHost = new ServiceHost(typeof(Microsoft.Samples.GettingStarted.CalculatorService))) { serviceHost.Open(); Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); serviceHost.Close(); } }
ServiceReference
web.config
<configuration> <system.serviceModel> <client> <!-- TODO: The address, binding, and contract attributes should match those in the service's config file. --> <endpoint name="main" address="http://localhost/ServiceModelSamples/CalculatorService" binding="basicHttpBinding" contract="Microsoft.Samples.GettingStarted.ICalculator" /> </client> </system.serviceModel> </configuration>
using ...ServiceReference
new MyServiceClient
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.