0

我在 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;
    }
}
4

2 回答 2

0

您需要使用 [DataContract] 属性标记类,并且数组应该是属性而不是字段。这就是您的 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);
于 2013-02-08T10:16:15.703 回答
0

我觉得与param变量有关的混乱;

WebServiceParam temp = new WebServiceParam();
string[] reportFields = new string[] { "invoiceNo", "sale", "item", "size", "missingQty", "Country", "auto" };
temp.param = reportFields;
serviceInstance.CreateReport(temp);
于 2013-02-08T10:07:52.787 回答