Код в моей программе:
[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>
Я использую Postman для проведения POST-тестирования.
Это использование URL в Почтальоне:
http://localhost: 49895 / service1.svc / REST / GetDocInfo_mobile_V
Это JSON использование в Почтальоне:
{"Labels":{"labellist":["5015058942/0001/0000","5015298272/0001/0000"]}}
docsv
всегда равен нулю в GetDocInfo_mobile_V
.
Почему это так?
У меня есть другая функция string GetEmpInfoByCard(string CardNo)
, которая успешно прошла проверку через Почтальон, но не GetDocInfo_mobile_V
.
Интересно, что пошло не так.