KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am trying to send some JSON data to a service I have created in c# and wcf. In Fiddler my POST request is as follows Fiddler: Request Header User-Agent: Fiddler Host: localhost Content-Length: 29 Content-Type: application/json; charset=utf-8 Request Body {sn:"2705", modelCode:1702 } Below is the service interface. That uses the WebInvoke attribute to manage the POST request [ServiceContract] public interface IProjectorService { [WebInvoke(Method="POST", UriTemplate="projectors", RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json )] [OperationContract] void RecordBreakdown(Record record); } The implementation of the service interface takes the variables passed in to the argument and uses ado to send this data to a SQL db. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)] public partial class ProjectorService : IProjectorService { public void RecordBreakdown(Record record) { //ado code to send data to db (ie do record.SerialNumber... } } POCO object to represent the multiple parameters [DataContract] public class Record { [DataMember] public string SerialNumber { get; set; } [DataMember] public int ModelCode { get; set; } } .svc file <%@ ServiceHost Language="C#" Debug="true" Service="ProjectorService" CodeBehind="~/App_Code/ProjectorService.cs" %> Web.config: <?xml version="1.0"?> <configuration> <appSettings> <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/> </appSettings> <system.web> <compilation debug="true" targetFramework="4.5"/> <httpRuntime targetFramework="4.5"/> </sys
Tags (comma-separated)
Save Edits
Cancel