Tuesday 11 October 2011

step 2 and 3

Step 2: I have created sample HelloWorld service, which will accept name as input and return with 'Hello' and name. Interface and implementation of the Service is shown below.
IMyService.cs
[ServiceContract]
public interface IMyService
{
    [OperationContract]
    string HelloWorld(string name);    

}
MyService.cs
public class MyService : IMyService
{

    #region IMyService Members

    public string HelloWorld(string name)
    {
        return "Hello " + name;
    }

    #endregion
}
Step 3: Service file (.svc) contains name of the service and code behind file name. This file is used to know about the service.
MyService.svc
<%@ ServiceHost Language="C#" Debug="true" 
Service="MyService" CodeBehind="~/App_Code/MyService.cs" %>
Step 4: Server side configurations are mentioned in the config file. Here I have mention only one end point which is configured to 'wsHttpBinding', we can also have multiple end point with differnet binding. Since we are going to hosted in IIS. We have to use only http binding. We will come to know more on endpoints and its configuration in later tutorial. Web.Config
<system.serviceModel>
  <services>
   <service behaviorConfiguration="ServiceBehavior" name="MyService">
 <endpoint address="http://localhost/IISHostedService/MyService.svc" 
 binding="wsHttpBinding" contract="IMyService">
 <identity>
 <dns value="localhost"/>
 </identity>
 </endpoint>
 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
   </service>
 </services>
 <behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
 <!-- To avoid disclosing metadata information, 
 set the value below to false and remove the 
 metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
 <!-- To receive exception details in faults for 
 debugging purposes, set the value below to true.  
 Set to false before deployment to avoid disclosing exception information -->
 <serviceDebug includeExceptionDetailInFaults="false"/>
 </behavior>
   </serviceBehaviors>
  </behaviors>
</system.serviceModel>

No comments:

Post a Comment