hello to all..
i wana consume my wcf service in HTMl pages through jquery... for this..i seen some code's but its not working .. i dint getting where am doing mistake..
here my code
IService1.svc
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "GET", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
List<RunDto> GetTeamData(int teamId, int weekNumber);
}
[DataContract]
public class RunDto
{
public string name1 = "SampleName";
[DataMember]
public string name
{
get { return name1; }
set { name1 = value; }
}
}
}
Service1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.ServiceModel.Activation;
namespace WcfService1
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
List<RunDto> ls = new List<RunDto>();
public List<RunDto> GetTeamData(int teamId, int weekNumber)
{
RunDto rn = new RunDto();
rn.name = teamId + " s " + weekNumber;
ls.Add(rn);
return ls;
}
}
}
web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="SampleService" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="IService1" name="samendpoint" behaviorConfiguration="AjaxBehaviour">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="AjaxBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<!--<modules runAllManagedModulesForAllRequests="true" />-->
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
jquery call in Html page
function GetTeamData(teamId, weekNumber) {
$.ajax(
{
async: true,
type: "GET",
contentType: "application/json; charset=utf-8",
url: "../../Services/RunningBarbusService.svc/GetTeamData",
dataType: "json",
data: '{"teamId":"' + teamId + '", "weekNumber":"' + weekNumber + '"}',
success: function (content) {
DisplayRun(map, content);
}
});
}
1st while excuting service only its getting error lik this
Error: Cannot obtain Metadata from http:
i need to consume my service from html page../. any possible ways... or any modifications to my code..
thanks.. in advance