Hello Everyone,
I need some help in how to call hosted WCF service from JQuery
I need to host this service and call the hosted WCF service from Jquery from another application...
My code as below..
IService1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
namespace WCF_REST_SOAP_JQuery
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string SayHello(string name);
}
}
Service1.svc
<pre lang="c#">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
namespace WCF_REST_SOAP_JQuery
{
[ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)]
public class Service1 : IService1
{
[WebInvoke(Method="GET",ResponseFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped)]
public string SayHello(string name)
{
return string.Format("Hello {0}", name);
}
}
}
Web.config
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WCF_REST_SOAP_JQuery.Service1"
behaviorConfiguration="ServiceBehaviour">
<endpoint address="JSON" binding="webHttpBinding" contract="WCF_REST_SOAP_JQuery.IService1"
behaviorConfiguration="JSONEndpointBehaviour"
bindingConfiguration="" name="RESTEP"></endpoint>
<endpoint address="SOAP" binding="basicHttpBinding" contract="WCF_REST_SOAP_JQuery.IService1"
name="basic"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="JSONEndpointBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value= "GET, POST"/>
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
please some one help in this.