ebruszl ebruszl - 4 months ago 42
JSON Question

WCF Rest Service Request Object' s Fields Always Null

I created a WCF Rest Service. I try to Post method usage. I send request from client, request getting from service method. But request object (CompanyDTO) fields values are null. Where is problem? I could' nt find.

Service post method



public void SaveCompany(CompanyDTO NewCompany)
{
try
{
CompanyManager manager = new CompanyManager();
manager.Save(NewCompany);

WebOperationContext ctx = WebOperationContext.Current;
ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK;
}
catch (Exception ex)
{
throw new FaultException(new FaultReason(ex.Message));
}
}


Contract service interface



[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "SaveCompany")]

void SaveCompany(CompanyDTO NewCompany);


CompantDTO
class



public class CompanyDTO
{
public string IDENTIFIER { get; set; }
public string TYPE { get; set; }
public string USER_TYPE { get; set; }
public string FIRST_NAME { get; set; }
public string MIDDLE_NAME { get; set; }
public string FAMILY_NAME { get; set; }
public string COMPANY_NAME { get; set; }
public Nullable<int> COMPANY_NO { get; set; }
public string LEGAL_OFFICE { get; set; }
public Nullable<System.DateTime> FOUNDATION_DATE { get; set; }
public string BOARDOFTRADE_NAME { get; set; }
public string BOARDOFTRADE_ID { get; set; }
public string MERSIS_NO { get; set; }
public string TAPDK_NO { get; set; }
public string TRADE_REGISTRATION_NO { get; set; }
public string TRADE_REGISTRATION_OFFICE { get; set; }
public string TAX_IDENTIFICATION_NO { get; set; }
public Nullable<System.DateTime> DIGITAL_SIGN_VALIDITY_DATE { get; set; }
public string TAX_OFFICE { get; set; }
public string TAX_OFFICE_CODE { get; set; }
public Nullable<short> STATUS { get; set; }
public Nullable<int> SYS_VERSION { get; set; }
public Nullable<System.DateTime> SYS_LAST_UPDATE { get; set; }
}


Client request body



{
"CompanyDTO":
{
"IDENTIFIER":"34501599398",
"TYPE":"1",
"USER_TYPE":"1",
"FIRST_NAME":"Ebru",
"MIDDLE_NAME":"sws",
"FAMILY_NAME":"sd",
"COMPANY_NAME":"NULL",
"COMPANY_NO": "123",
"LEGAL_OFFICE": "DSF",
"FOUNDATION_DATE":"2015-03-02",
"BOARDOFTRADE_NAME":"SAD",
"BOARDOFTRADE_ID":"ASD",
"MERSIS_NO":"DASD",
"TAPDK_NO":"NULASDASDL",
"TRADE_REGISTRATION_NO":"NULL",
"TRADE_REGISTRATION_OFFICE":"ADS",
"TAX_IDENTIFICATION_NO":"NUASDSALL",
"DIGITAL_SIGN_VALIDITY_DATE": "2015-03-02",
"TAX_OFFICE":"ASDAD",
"TAX_OFFICE_CODE":"ASDA",
"STATUS": "1",
"SYS_VERSION" : "1",
"SYS_LAST_UPDATE": "2015-03-02"
}
}

Answer

It seems you need to get rid of "CompanyDTO" in your json, so it looks likes this:

{  
   "IDENTIFIER":"34501599398",
   "TYPE":"1",
   "USER_TYPE":"1",
   "FIRST_NAME":"Ebru",
   "MIDDLE_NAME":"sws",
   "FAMILY_NAME":"sd",
   "COMPANY_NAME":"NULL",
   "COMPANY_NO": "123",
   "LEGAL_OFFICE": "DSF",
   "FOUNDATION_DATE":"2015-03-02",
   "BOARDOFTRADE_NAME":"SAD",
   "BOARDOFTRADE_ID":"ASD",
   "MERSIS_NO":"DASD",
   "TAPDK_NO":"NULASDASDL",
   "TRADE_REGISTRATION_NO":"NULL",
   "TRADE_REGISTRATION_OFFICE":"ADS",
   "TAX_IDENTIFICATION_NO":"NUASDSALL",
   "DIGITAL_SIGN_VALIDITY_DATE": "2015-03-02",
   "TAX_OFFICE":"ASDAD",
   "TAX_OFFICE_CODE":"ASDA",
   "STATUS": "1",
   "SYS_VERSION" : "1",
   "SYS_LAST_UPDATE": "2015-03-02"
}