wcfrest大數據
『壹』 WCF+REST 返回Json數據有雙引號怎麼去掉
[OperationContract][WebGet(UriTemplate = "Hello")]Stream Get(string name); public Stream Hello(string name) { string jsCode = "Hello"; return new MemoryStream(Encoding.UTF8.GetBytes(jsCode)); }找到解決復辦法啦,制WebMessageFormat.Json就是會在返回值上加雙引號上面是我的解決辦法,希望能幫到一些人
『貳』 WCF4.0中REST模式下,URI與其相對應的方法參數是否只能為string
一、WCFREST專用POST方法.1、 建立WCFREST方法[ServiceContract]public interface IBookingBizService{ [WebInvoke(UriTemplate = "setdeliver", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] [OperationContract()] OperateResult SetDeliver(string args); }1.2、 POST調用WCFREST方法private string UseHttpWebApproach(string serviceUrl, string resourceUrl, string method, string requestBody){ string responseMessage = null; var request = WebRequest.Create(string.Concat(serviceUrl, resourceUrl)) as HttpWebRequest; if (request != null) { request.ContentType = "application/json"; request.Method = method; } if (method == "POST" && requestBody != null) { byte[] requestBodyBytes = (requestBody); request.ContentLength = requestBodyBytes.Length; using (Stream postStream = request.GetRequestStream()) postStream.Write(requestBodyBytes, 0, requestBodyBytes.Length); } if (request != null) { var response = request.GetResponse() as HttpWebResponse; if (response.StatusCode == HttpStatusCode.OK) { Stream responseStream = response.GetResponseStream(); if (responseStream != null) { var reader = new StreamReader(responseStream); responseMessage = reader.ReadToEnd(); } } else { responseMessage = response.StatusDescription; } } return responseMessage;} private static byte[] (string requestBody){ byte[] bytes = null; var serializer1 = new DataContractJsonSerializer(typeof(string)); var ms1 = new MemoryStream(); serializer1.WriteObject(ms1, requestBody); ms1.Position = 0; var reader = new StreamReader(ms1); bytes = ms1.ToArray(); return bytes;}調用WCF REST方法和一般的POST方法有所不同,區別在於發送前對數據的編碼,採用DataContractJsonSerializer進行序列化。一般的對POST方法的調用採用如何數據編碼private static byte[] ToByteArray(string requestBody){ byte[] bytes = null; bytes = Encoding.UTF8.GetBytes(requestBody); return bytes;} 如果要建立通用的POST調用服務,不建議採用WCFREST形式,如果只是針對.net平台的調用到時沒有關系。
『叄』 請教如何通過WCF傳輸大數據量數據
又是一個把自己架在火上烤的需求啊,
如果不考慮傳輸因素,可以調整wcf配置,提升傳遞的容量,如果是對象傳遞可能還要調整對象層次的深度
『肆』 請教如何通過WCF傳輸大數據量數據
就是直接把DataSet 類型作為參數直接傳遞給服務端
WCF默認支持這么做,直接傳Datatable不行。
你看一下 「服務引用設置」中你選的集合類型是什麼,我選的是System.Array
字典集合類型是默認第一項 System.Collections.Generic.Dictionary
『伍』 將WCF Rest項目部署在IIS上並綁定了一個埠之後,其他人可以用瀏覽器成功查看XXXXX/help,但是相同功能的
WCF項目的話,其他人要能看到*.svc才能正常工作的。可以再VS中添加服務引用看看報什麼錯誤。
『陸』 wcf rest post服務端無法接收數據,該怎麼處理
ServiceContract(NameSpace="UserInfo")]
public interface IUser
{
[OperationContract]
[WebInvoke(UriTemplate="/AddUser",Method="POST",ResponseFormat=WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.WrappedRequest)]
『柒』 用C# WCF做一個REST的WebService,用Get可以獲得數據。但是用POST方法總是返回400錯誤。
感覺不像是namespace的問題。
樓主如果在本地訪問外網的: "http://mydomain.com/Testservice.svc/FeedBack/Submit",網址,會有400錯誤么?
如果有內,那應該是你發布端的問題。。容
『捌』 WCF,WebAPI,WCFREST和WebService的區別
Web Service
It is based on SOAP and return data in XML form.
It support only HTTP protocol.
It is not open source but can be consumed by any client that understands xml.
It can be hosted only on IIS.
WCF
It is also based on SOAP and return data in XML form.
It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.
The main issue with WCF is, its tedious and extensive configuration.
It is not open source but can be consumed by any client that understands xml.
It can be hosted with in the applicaion or on IIS or using window service.
WCF Rest
To use WCF as WCF Rest service you have to enable webHttpBindings.
It support HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively.
To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files
Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified
It support XML, JSON and ATOM data format.
Web API
This is the new framework for building HTTP services with easy and simple way.
Web API is open source an ideal platform for building REST-ful services over the .NET Framework.
Unlike WCF Rest service, it use the full featues of HTTP (like URIs, request/response headers, caching, versioning, various content formats)
It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.
It can be hosted with in the application or on IIS.
It is light weight architecture and good for devices which have limited bandwidth like smart phones.
Responses are formatted by Web API』 MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.
To whom choose between WCF or WEB API
Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, plex communication etc.
Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.
Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).
Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.
『玖』 wcf rest maxreceivedmessagesize最大多少
這個跟是否REST沒有關系,默認16K,最大是 byte[] 數組的最大長度,約100MB。
如果需要大體量傳輸,微軟給出的建議是 用Stream作為WCF服務介面的參數。
『拾』 wcf rest怎麼包裝多參數
通過VS2010的Extension Manager,可以下載一個「WCF REST Service Template」。通過這個我們可以快速版創建一個WCF REST服務。它是一個創建在權Web Application工程里的服務。和前一篇介紹的WCF服務不同的是在Globel.asax中的Application_Start事件中注冊服務。並且注冊的"TaskService"自動成為服務的基地址,即 http://<machine_name>:<port>/TaskService/
服務端直接通過Linq2Entities操作DB,為了返回JSON的數據,參數和返回值都設計為POCO類。在Linq2Entities生成代碼後,又拷貝了一份進行刪減修改為POCO類。(現在有一個ADO.NET POCO Generator 的t4模板,不知道能否簡化我現在的做法...)