WCF休息服务请求对象'字段始终为空

时间:2016-03-02 16:17:36

标签: json web-services wcf rest wcf-rest

我创建了一个WCF Rest服务。我尝试发布方法用法。我从客户发送请求,请求从服务方法获取。但请求对象(CompanyDTO)字段值为空。哪里有问题?我可以'找不到。

服务职位方法

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));
    }
}

合同服务界面

[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; }
}    

客户请求正文

{
    "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"
    }
}

1 个答案:

答案 0 :(得分:0)

你的json中似乎需要摆脱"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"
}