开发者

Send large JSON data to WCF Rest Service

开发者 https://www.devze.com 2023-01-01 11:43 出处:网络
I have a client web page that is sending a large json object to a proxy service on the same domain a开发者_StackOverflow中文版s the web page.

I have a client web page that is sending a large json object to a proxy service on the same domain a开发者_StackOverflow中文版s the web page.

The proxy (an ashx handler) then forwards the request to a WCF Rest Service. Using a WebClient object (standard .net object for making a http request)

The JSON successfully arrives at the proxy via a jQuery POST on the client webpage.

However, when the proxy forwards this to the WCF service I get a Bad Request - Error 400

This doesn't happen when the size of the json data is small

The WCF service contract looks like this

[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
CarConfiguration CreateConfiguration(CarConfiguration configuration);

And the DataContract like this

[DataContract(Namespace = "")]
 public class CarConfiguration
 {
        [DataMember(Order = 1)]
        public int CarConfigurationId { get; set; }
        [DataMember(Order = 2)]
        public int UserId { get; set; }
        [DataMember(Order = 3)]
  public string Model { get; set; }
        [DataMember(Order = 4)]
        public string Colour { get; set; }
        [DataMember(Order = 5)]
        public string Trim { get; set; }
        [DataMember(Order = 6)]
        public string ThumbnailByteData { get; set; }
        [DataMember(Order = 6)]
        public string Wheel { get; set; }
        [DataMember(Order = 7)]
        public DateTime Date { get; set; }
  [DataMember(Order = 8)]
  public List<string> Accessories { get; set; }
  [DataMember(Order = 9)]
        public string Vehicle { get; set; }
  [DataMember(Order = 10)]
  public Decimal Price { get; set; }
 }

When the ThumbnailByteData field is small, all is OK. When it is large I get the 400 error

What are my options here?

I've tried increasing the MaxBytesRecived config setting but that is not enough

Any ideas?


I would also tweak maxStringContentLength and maxBytesPerRead. Also make sure that whatever binding configuration you set up, you're actually using it in all the right places.

This thread captures pretty well all the things that can go wrong when you are dealing with a large string in WCF message input, so I'd follow the guidance here: Sending large strings to a WCF web service

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号