我在Web服务中有以下类:
[Serializable]
public class WebServiceParam
{
public string[] param;
}
在客户端应用程序中:
string[] reportFields = new string[] { "invoiceNo", "sale", "item", "size", "missingQty", "Country", "auto" };
param.ReportFields = reportFields;
serviceInstance.CreateReport(param);
但是,字符串数组成员是“null”
这是我的网络服务类:
[WebService(Description = "Service related to producing various report formats", Namespace = "http://www.apacsale.com/ReportingService")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class ReportingService : System.Web.Services.WebService
{
ReportingServiceImpl m_reporting;
[WebMethod]
public string CreateReport(ReportingParameters param)
{
if (param != null)
{
m_reporting = new ReportingServiceImpl(param);
m_reporting.Create();
return m_reporting.ReturnReport();
}
return null;
}
}
答案 0 :(得分:0)
我觉得与param
变量有关的混淆;
WebServiceParam temp = new WebServiceParam();
string[] reportFields = new string[] { "invoiceNo", "sale", "item", "size", "missingQty", "Country", "auto" };
temp.param = reportFields;
serviceInstance.CreateReport(temp);
答案 1 :(得分:0)
您需要使用[DataContract]属性标记该类,并且该数组应该是property而不是field。这就是WebServiceParam的外观:
[DataContract]
public class WebServiceParam
{
[DataMember]
public string[] Param {get; set;}
}
并且服务接口将是这样的:
[ServiceContract]
public interface IService
{
[OperationContract]
void CreateReport(WebServiceParam parameters);
}
现在您可以使用:
WebServiceParam wsParam = new WebServiceParam();
wsParam.Param = new string[] { "invoiceNo", "sale", "item", "size", "missingQty", "Country", "auto" };
serviceInstance.CreateReport(wsParam);