Friday, 13 March 2015

WCF SERVICE CONFIGURING


Configure your WCF service in "web.config" as below ;-
[web.config]

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="web"
                 receiveTimeout="00:30:00"
                 sendTimeout="00:30:00"></binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="namespace.serviceName"  behaviorConfiguration="web">
        <endpoint name="mex" address="" binding="basicHttpBinding"         contract="namespace.serviceInterface">
        </endpoint>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="web">
          <!-- To enable metadata information -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details  -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

[Iservice1.cs]
using System.ServiceModel;
using System.ServiceModel.Web;

namespace namespaceName
{
 
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebInvoke(UriTemplate = "/method1/{arg1}", ResponseFormat =    WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]

        string method1(string arg1);

        [OperationContract]
        [WebInvoke(UriTemplate = "/method2/{arg1}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
        string method2(string arg1);
    }

}

[Service1.svc]
using System;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;

namespace NamespaceName
{
    public class Service1 : IService1
    {
        public string method1(string arg1)
        {
            //do implementation here
        }

        public string method2(string arg1)
        {
             //do implementation here
        }
    }
}

Note:deploy/publish the service as mentioned in other posts

No comments:

Post a Comment