rest - Put/Post json not working with ODataController if Model has Int64 -


i have data object int64 column:

[tableattribute(name="dbo.vw_relationlineofbusiness")] [dataservicekey("providerrelationlobid")]  public partial class relationlineofbusiness {      #region column mappings     private system.guid _lineofbusiness;     private system.string _contractnumber;     private system.nullable<system.int32> _providertype;     private system.string _insuredprovidertype;     private system.guid _providerrelationlobid;     private system.string _lineofbusinessdesc;     private system.string _culturecode;     private system.string _contractdesc;     private system.nullable<system.guid> _providerrelationkey;     private system.string _providerrelationnbr;     **private system.int64 _assignednbr;** 

when post/put object through odata controller using httpclient , newtsonsoft:

partial class relationlineofbusinesscontroller : odatacontroller {

public httpresponsemessage putrelationlineofbusiness([fromodatauri] system.guid key, invidasys.vidapro.model.relationlineofbusiness entity)

the entity object null , error in modelstate :

"cannot convert primitive value expected type 'edm.int64'. see inner exception more details."

i noticed when on object using below url:

invidasys.rest.service/vidapro/relationlineofbusiness(guid'c6824edc-23b4-4f76-a777-108d482c0fee')

my json looks following - noticed assignednbr treated string.

{ "odata.metadata":"invidasys.rest.service/vidapro/$metadata#relationlineofbusiness/@element", "lineofbusiness":"ba129c95-c5bb-4e40-993e-c28ca86fffe4","contractnumber":null,"providertype":null, "insuredprovidertype":"pcp","providerrelationlobid":"c6824edc-23b4-4f76-a777-108d482c0fee", "lineofbusinessdesc":"medicaid","culturecode":"en-us","contractdesc":null, "providerrelationkey":"a2d3b61f-3d76-46f4-9887-f2b0c8966914","providerrelationnbr":"4565454645", "assignednbr":"1000000045","ispar":true,"providertypedesc":null,"insuredprovidertypedesc":"primary care physician", "startdate":"2012-01-01t00:00:00","enddate":"2014-01-01t00:00:00","created":"2014-06-13t10:59:33.567", "createdby":"michael","updated":"2014-06-13t10:59:33.567","updatedby":"michael" }

when put httpclient json showing in restful services following , json assignednbr column not in quotes results in restful services failing build json object. played json , put assignednbr in quotes , request goes through correctly.

{"assignednbr":1000000045,"contractdesc":null,"contractnumber":null,"created":"/date(1402682373567-0700)/", "createdby":"michael","culturecode":"en-us","enddate":"/date(1388559600000-0700)/","insuredprovidertype":"pcp", "insuredprovidertypedesc":"primary care physician","ispar":true,"lineofbusinessdesc":"medicaid", "lineofbusiness":"ba129c95-c5bb-4e40-993e-c28ca86fffe4","providerrelationkey":"a2d3b61f-3d76-46f4-9887-f2b0c8966914", "providerrelationlobid":"c6824edc-23b4-4f76-a777-108d482c0fee","providerrelationnbr":"4565454645","providertype":null, "providertypedesc":null,"startdate":"/date(1325401200000-0700)/","updated":"/date(1408374995760-0700)/","updatedby":"ed"}

the reason wanted expose our business model restful services hide data validation , expose our databases in format easy develop against. looked @ dataservicecontext see if work , uses xml communicate between restful services , client. work dataservicecontext not give level of messaging httprequestmessage/httpresponsemessage gives me informing users on errors/missing information post.

we planning on supporting multiple devices our restful services platform requires can use newtonsoft json microsoft's datacontractjsonserializer if need be.

my question restful service standpoint - there way can configure/code restful services take in assignednbr in json without quotes.

or json standpoint way can json built without getting serializing business nor want our clients have deal custom serializers if want write own apps against our restful services.

any suggestions?

thanks.

i think can migrate web api 2.2 odata v4. here's information:

announcing release of asp.net mvc 5.2, web api 2.2 , web pages 3.2

odata v4 spec says:

3.2 controlling representation of numbers

the ieee754compatible=true format parameter indicates service must serialize edm.int64 , edm.decimal numbers (including odata.count, if requested) strings. if not specified, or specified ieee754compatible=false, numbers must serialized json numbers.

this enables support javascript numbers defined 64-bit binary format ieee 754 values [ecmascript] (see section 4.3.1.9) resulting in integers losing precision past 15 digits, , decimals losing precision due conversion base 10 base 2. odata json payloads format edm.int64 , edm.decimal values strings must specify format parameter in media type returned in content-type header.

so, payload as:

@"{      ""lineofbusiness"": ""ba129c95-c5bb-4e40-993e-c28ca86fffe4"",     ""assignednbr"": ""1000000045""   }"; 

you should set:

request.content.headers.contenttype = mediatypeheadervalue.parse("application/json;ieee754compatible=true"); 

otherwise, shouldn't.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -