Hi All,
I developed one WCF Rest Service. get method and post methods how to call wcf rest service from web client. My code like this
----WCF Interface methods
[OperationContract]
[WebInvoke(UriTemplate = "UpdateTrackDetails",
Method = "POST", RequestFormat = WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
string UpdateTrackDetails(string trackdetails);
---WCF Implementation of Interface
public string UpdateTrackDetails(string trackdetails)
{
string time = "";
DateTime dt = new DateTime();
try
{
// System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();
string result = "0";
TrackDetails _BusTrack = JsonConvert.DeserializeObject<trackdetails>(trackdetails);
time = _BusTrack.TrackTime;
string daa = Convert.ToDateTime(time).ToString("dd/MM/yyyy");
dt = Convert.ToDateTime(daa);
using (var context = new SchoolBusTrackEntities())
{
context.BusTrackDetails.Add(
new BusTrackDetail
{
BusID = Convert.ToInt32(_BusTrack.BusID),
Latitude = _BusTrack.Latitude,
Longitude = _BusTrack.Longitude,
// TrackTime = DateTime.Now
TrackTime = dt,
TrackTime1 = time
}
);
result = context.SaveChanges().ToString();
}
return "result";
}
catch (Exception ex)
{
return ex.Message;
}
}
---WCF Config File
<system.servicemodel>
<services>
<service name="BusTrackService.SchoolBusTrack" behaviorconfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="BusTrackService.ISchoolBusTrack" behaviorconfiguration="Web">
<identity>
<dns value="localhost">
<endpoint name="mexHttpBinding">
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
<behaviors>
<servicebehaviors>
<behavior name="ServiceBehavior">
<datacontractserializer maxitemsinobjectgraph="10000000">
<servicemetadata httpgetenabled="true">
<servicedebug includeexceptiondetailinfaults="false">
<behavior>
<servicemetadata httpgetenabled="true">
<servicedebug includeexceptiondetailinfaults="false">
<endpointbehaviors>
<behavior name="Web">
<datacontractserializer maxitemsinobjectgraph="10000000">
<webhttp helpenabled="true" defaultoutgoingresponseformat="Json" defaultbodystyle="Bare" automaticformatselectionenabled="true">
<!--<webhttp>-->
<bindings>
<webhttpbinding>
<binding maxreceivedmessagesize="2147483647">
<readerquotas maxarraylength="2147483647" maxstringcontentlength="2147483647">
<servicehostingenvironment multiplesitebindingsenabled="true">
<system.webserver>
<modules runallmanagedmodulesforallrequests="true">
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directorybrowse enabled="true">
<system.diagnostics>
<trace autoflush="true"> <sources>