如何将对象发送到visualbasic asp.net后面的WebService代码

时间:2013-10-29 22:50:16

标签: asp.net vb.net web-services class serialization

我在我的项目中使用引用的Web服务,我需要传递两个参数:我的类名为“clPerson.vb”,另一个类的ArrayList传递给webservice方法。

在我的网页中,我需要做这样的事情:

Protected Sub WebPageSub()
    Dim ObjPerson = New WebPage.clPerson(84) '84 is IDPerson
    Dim ALDocuments As ArrayList = WebPage.getArrPerDocs(84, "T") 'this returns an arraylist of clDocuments class, returns all the documents that person 84 has, "T" is the identified for documents

    Dim wsSave As WebServiceExample 'WebService must save the data I Send.
    wsSave.InsertData(ObjPerson,ALDocuments) 'I send an arraylist and
End Sub


在我的Web服务器中,应该像这样工作

<WebMethod()>
Public sub InsertData(ObjPerson As clPerson, DocsArray as ArrayList) 
    ' ..SAVE DATA
End Sub

注意:clPerson和clDocuments是我的主要项目和我的Web服务中的类。

1 个答案:

答案 0 :(得分:0)

我修复了它实例化两个类(WebService.clPerson和WebPage.clPerson),然后我手动分配了这样的每个属性。

然后我向clPerson类添加一个Object()类型属性,以保存clDocument类的ArrayList,并且只能向WebService发送一个参数。

    Dim cont As Integer = 0
    Dim CodErr As String = Nothing

    Dim ObjPerson = New webpage.clPerson(84)
    Dim arrDocPers As ArrayList = getArrPerDocs(84, "T")
    Dim ArrObj(arrDeReq.Count - 1) As Object

    Dim ObjWS As New WebService.wsObj 'WebService Object
    Dim WSObjPerson As New WebService.clPerson
    Dim WSObjDocs As WebService.clDocuments


    For Each arrDeReqaux As WebPage.clDocuments In arrDocPers 
        WSObjDocs = New WebService.clDocuments
        WSObjDocs.ID = arrDeReqaux.ID
        WSObjDocs.DUI= arrDeReqaux.DUI
        WSObjDocs.PassportID = arrDeReqaux.PassportID
        WSObjDocs.LicenceID= arrDeReqaux.LicenceID
        ArrObj(cont) = WSObjDocs
        cont += 1
    Next


    WSObjPerson.FullName= ObjPerson.FullName
    WSObjPerson.Age = ObjPerson.Age
    WSObjPerson.propALDocs = ArrObj

    CodErr = ObjWS.InsertPerson(WSObjPerson)