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模板,不知道能否简化我现在的做法...)