2013-02-08 41 views
0

我已經在web服務的下列類:傳遞與字符串數組成員的類到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); 

但是,字符串數組成員是「空「

+0

您有權發佈WebService類。至少是您創建的Web方法。 –

回答

0

我覺得有一個混淆與param變量有關;

WebServiceParam temp = new WebServiceParam(); 
string[] reportFields = new string[] { "invoiceNo", "sale", "item", "size", "missingQty", "Country", "auto" }; 
temp.param = reportFields; 
serviceInstance.CreateReport(temp); 
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); 
0

這是一個Web服務,不是WCF服務。因此,服務類用[WebService]和方法[WebMethod]屬性裝飾。我用[DataContract]裝飾了參數類,用[DataMember]裝飾了字符串數組屬性,但它不起作用....當調用web方法時,字符串數組屬性爲null。

問候, 德

0

這裏是我的web服務類:

[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; 
    } 
} 
相關問題