wcf-rest

JSON data returned from WCF service contains escape characters

六眼飞鱼酱① 提交于 2019-12-17 17:13:07
问题 I have a working WCF - WPF application working, however I'm looking for some optimization. Below is my code where a WCF restful service is exposing a JSON array, and a WPF UI is receiving it without any problem. WCF: public clsStatus[] GetAllStatus() { DataTable dt = new DataTable(); List<clsStatus> lstGetAllStatus = new List<clsStatus>(); try { dt = // My Data Table foreach (DataRow dr in dt.Rows) { dcStatus objGetAllStatus = new clsStatus(); objGetAllStatus.Id = Convert.ToInt32(dr["Id"]);

jQuery .ajax() POST Request throws 405 (Method Not Allowed) on RESTful WCF

泪湿孤枕 提交于 2019-12-17 03:02:09
问题 I am sending a post request to a RESTFUL WCF service application. I am able to successfully send a POST request through Fiddler. However when I do this through the jQuery Ajax method the function returns the following to the Chrome Developer Console: OPTIONS http://www.example.com/testservice/service1.svc/GetData 405 (Method Not Allowed) jquery.min.js:6 But then a second after logs: Object {d: "You entered 10"} testpost.html:16 What this tells me is that jQuery is sending a OPTIONS request,

How WCF decides when return SOAP or JSON depending on the request?

无人久伴 提交于 2019-12-13 16:33:59
问题 I just created my first WCF REST service. I wanted it to return JSON, so i especified the response format. At first, I was frustrated because it was returning SOAP all the time and I didn't know why, but I saw that a blogger was using Fiddler, so I tried with it and then I got a JSON response. I think that the reason is because Fiddler is not sending this HTTP header: Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 But then I tried to craft a request using this header:

returning total count of records

倾然丶 夕夏残阳落幕 提交于 2019-12-13 04:59:21
问题 I am using WCF rest service and i want to return total record count just as we have inlinecount in webapi or breeze. My method in WCF is [WebGet(UriTemplate = "GiveMeNamesOfStudents", ResponseFormat = WebMessageFormat.Json)] public List<MyDataClass> GiveMeNamesOfStudentsList() { var returnData = (from myentity in myEntityRepository.AsQueryable() select new MyDataClass { Id = myentity.Id, Name = myentity.Name }).Skip(PageSize * PageNo).Take(PageSize).ToList(); return returnData; } How can i

Unable to upload an image with parameters to wcf rest service

好久不见. 提交于 2019-12-13 04:13:57
问题 Please dont mark it as Duplicate. I have treid many times but failed. i am getting stream content and saving my image with static name. But i am unable to sending the image file-name,extension parameters to that post URL. my code is like below My Web.Config <?xml version="1.0" encoding="UTF-8"?> <system.web> <compilation debug="true" targetFramework="4.0"/> </system.web> <system.serviceModel> <services> <service name="PracticeWcfService1.Service1" behaviorConfiguration="ServiceBehaviour">

Could not make Json Request body from Iphone

假如想象 提交于 2019-12-13 03:38:03
问题 I am a .Net Software developer .I have Created a WCF Rest API for User Validation Following is its signature. [OperationContract] [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/Validate", Method = "POST")] UserListResponse ValidateUser(Login obj); It is working fine in fiddler with following Request Body {"Username":"admin",Password:"111"} My problem is, it is not accessible from Iphone using http

WCF RESTful Service - POST- WebFaultException complete sample

二次信任 提交于 2019-12-13 03:21:21
问题 I searched so many links but none actually works and most of them doesnot give correct client code. There is something I am missing. I have below exception class [DataContract] public class MyException { public MyException(Exception ex) { Message = ex.Message; StackTrace = ex.StackTrace; ExceptionType = ex.GetType(); } [DataMember] public string Message { get; set; } [DataMember] public string StackTrace { get; set; } //[DataMember] // This is having issues. On client side WebException

WCF: Changing ClientCredentials produces “Manual addressing is enabled on this factory, so all messages sent must be pre-addressed.”

二次信任 提交于 2019-12-12 17:20:10
问题 can anyone help, i am trying to call a rest service via the channel factory but sending along my credentials... The rest service uses Windows authentication. But with the following code i get "Manual addressing is enabled on this factory, so all messages sent must be pre-addressed." error when using GetMessage I know my service works as if i remove Windows authentication it works! BUt with windows authentication on and not changing clientCredentials i get BAD REQUEST whioch i think is normal.

How to create query expression for Odata for get by Id

北慕城南 提交于 2019-12-12 08:57:47
问题 I have created an OData service and now I am trying to consume this service at client side. I wants to create an expression such as for the below url in the c# query expression- http://odata.org/Product-Service/Product(150) The above url is working fine in browsers but I want to create query expression in the C# for the above url. Any help would be greatly appreciable. 回答1: You could use a DataServiceContext + DataServiceQuery in System.Data.Services.Client to hit the Url. Remember no query

WCF/RESTful DataContract deserialization issue

天涯浪子 提交于 2019-12-12 04:31:53
问题 I am trying to implement a restful service in WCF, but am having issues in that the service is unable to deserialize the xml being passed to it. It is trying to map the root element to the operation contract rather than to the data contract. For example, with the following XML packet, <MyObject> <MyField1>asdf</MyField1> <MyField2>1234</MyField2> ... </MyObject> it's unable to deserialize MyObject as the input message since it expects the operation contract at that level. I don't want to just