C# 邮递员投递到WCF对象为空

C# 邮递员投递到WCF对象为空,c#,wcf,postman,C#,Wcf,Postman,我的程序中的代码: [ServiceContract] public interface IService1 { [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] string GetDocInfo_mobile_V(Labels docs); } [DataCo

我的程序中的代码:

[ServiceContract]
public interface IService1
{
    [OperationContract]
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    string GetDocInfo_mobile_V(Labels docs);
}

[DataContract]
public class Labels
{
    private List<string> label;

    [DataMember]
    public List<string> labellist
    {
        get
        {
            return label;
        }
        set
        {
            label = value;
        }
    }
}

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
    private static readonly NLog.Logger nLogger = NLog.LogManager.GetCurrentClassLogger();

    public string GetDocInfo_mobile_V(Labels docsv)
    {
        try
        {
            Documents docs = new Documents();
            foreach (var docv in docsv.labellist)
            {
                string[] info = docv.Split('/');
                if (info.Length > 1)
                {
                    Document doc = new Document { Doc_item_num = info[1], Doc_num = info[0] };
                    docs.Listdocument.Add(doc);
                }
            }
            return GetDocInfo_mobile(docs);
        }
        catch (Exception exception)
        {
            nLogger.Error(exception);
            throw;
        }
    }
}
我的系统中的Web.config:

<system.serviceModel>
<services>
  <service behaviorConfiguration="SmartLockerWS.Service1" name="SmartLockerWS.Service1">
    <endpoint address="" binding="wsHttpBinding" contract="SmartLockerWS.IService1">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <endpoint address="REST" binding="webHttpBinding" behaviorConfiguration="restfulbehavior" bindingConfiguration="" contract="SmartLockerWS.IService1"></endpoint>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="restfulbehavior">
      <webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" defaultBodyStyle="WrappedRequest"/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="SmartLockerWS.Service1">
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
我用邮递员做后期测试

这是邮递员使用的URL:

这是Postman中JSON的用法: {标签:{标签列表:[5015058942/0001/00005015298272/0001/0000]}

docsv在GetDocInfo\u mobile\u V中始终为空。 为什么呢

我还有另外一个函数字符串GetEmpInfoByCardstring CardNo,它通过Postman测试成功,但没有通过GetDocInfo\u mobile\u V。 我想知道出了什么问题

您应该将attibute添加到labellist:

编辑:

您还需要通过以下方式发送请求:

{docs:{labellist:[5015058942/0001/00005015298272/0001/0000]}

您应该将attibute添加到labellist:

编辑:

您还需要通过以下方式发送请求:


{docs:{labellist:[5015058942/0001/00005015298272/0001/0000]}

我想你忘了给labellistI添加DataMember属性我想你忘了给labellistI添加DataMember属性我更新了我的代码,结果相同,仍然收到null。以{docs:{labellist:[5015058942/0001/00005015298272/0001]}的身份发送请求没有,仍然为空。它应该可以工作,我认为您在通过邮递员发送请求方面有问题。请检查如何通过邮递员发布Json数据我检查了你的邮递员屏幕,正如我在回答中提到的,它应该是docs而不是docsvI更新了我的代码,结果相同,仍然收到null。发送请求为{docs:{labellist:[5015058942/0001/00005015298272/0001/0000]}不,仍然为null。它应该可以工作,我想你在通过邮递员发送请求方面有问题。请检查如何通过邮递员发布Json数据我检查了您的邮递员屏幕,正如我在回答中提到的,它应该是docs而不是docsv
[DataContract]
public class Labels
{
    private List<string> label;

    [DataMember]
    public List<string> labellist
    {
        get
        {
            return label;
        }
        set
        {
            label = value;
        }
    }
}