0

XML シリアル化を使用するのはこれが初めてで、ネストされた繰り返しテーブルを送信できるかどうか、または配列内の配列をシリアル化する方法がわかりません。

「リソース」繰り返しテーブル内に「週」繰り返しテーブルを含む Infopath フォームがあります。これは XML 出力です。

<my:AllocateResource>
    <my:Resource>
        <my:Person>
            <my:DisplayName>User 1</my:DisplayName>
            <my:AccountId>49808</my:AccountId>
            <my:AccountType>User</my:AccountType>
        </my:Person>
    </my:Resource>
    <my:Weeks>
        <my:WeekNumber>24</my:WeekNumber>
        <my:Hours>20</my:Hours>
    </my:Weeks>
    <my:Weeks>
        <my:WeekNumber>28</my:WeekNumber>
        <my:Hours>15</my:Hours>
        </my:Weeks>
    <my:RequestID>1</my:RequestID>
    <my:StartDate>2013-08-01</my:StartDate>
    <my:EndDate>2013-08-14</my:EndDate>
</my:AllocateResource>
<my:AllocateResource>
    <my:Resource>
        <my:Person>
            <my:DisplayName>User2</my:DisplayName>
            <my:AccountId>49841</my:AccountId>
            <my:AccountType>User</my:AccountType>
        </my:Person>
    </my:Resource>
    <my:Weeks>
        <my:WeekNumber>25</my:WeekNumber>
        <my:Hours>10</my:Hours>
    </my:Weeks>
    <my:RequestID>2</my:RequestID>
    <my:StartDate>2013-08-01</my:StartDate>
    <my:EndDate>2013-08-14</my:EndDate>
</my:AllocateResource>

SQL データベースに書き込むために、これを ASMX Web サービスにシリアル化しようとしています。繰り返しテーブルを 1 つだけ使用して動作させることができますが、2 つ目の繰り返しテーブルを内部に配置しようとすると、データが取得されません。これは、シリアル化された RepeatingTable クラスです。

<System.Xml.Serialization.XmlRootAttribute([Namespace]:="http://schemas.microsoft.com/office/infopath/2003/myXSD/2013-08-12T19:02:25", IsNullable:=False)> _Public Class AllocateResources
<System.Xml.Serialization.XmlArray("AllocateResource")> _
Public Resource As Resource()
Public RequestID As Integer
Public StartDate As Date
Public EndDate As Date

End Class
    Public Class Resource
    Public Person As Person()
    Public Weeks As Weeks()
End Class

Public Class Weeks
    Public WeekNumber As Integer
    Public Hours As Decimal
End Class

Public Class Person
    Public DisplayName As String
    Public AccountId As String
    Public AccountType As String
End Class

私の Web サービス SOAP Evelope は次のようになります。Person ノードと Weeks ノードに子ノードが含まれていないことに注意してください。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SubmitRepeatingTable xmlns="http://tempuri.org/">
      <myRepTable xmlns="http://schemas.microsoft.com/office/infopath/2003/myXSD/2013-08-12T19:02:25">
        <AllocateResource>
          <Resource>
            <Person xsi:nil="true" />
            <Weeks xsi:nil="true" />
          </Resource>
          <Resource>
            <Person xsi:nil="true" />
            <Weeks xsi:nil="true" />
          </Resource>
        </AllocateResource>
        <RequestID>int</RequestID>
        <StartDate>dateTime</StartDate>
        <EndDate>dateTime</EndDate>
      </myRepTable>
    </SubmitRepeatingTable>
  </soap:Body>
</soap:Envelope>

これは私の WebService コードです:

 Public Sub SubmitRepeatingTable(myRepTable As RepeatingTable)

        Dim myConnection As SqlConnection = New SqlConnection()
        myConnection = New SqlConnection(connectionString)
        myConnection.Open()
        Dim Command As New SqlClient.SqlCommand("usp_add_allocation")
        Command.CommandType = CommandType.StoredProcedure
        Command.Connection = myConnection

        For i As Integer = 0 To myRepTable.Resource.Length - 1
            Dim RequestID As Integer = myRepTable.RequestID
            Dim AccountID As String = myRepTable.Resource(i).Person(i).AccountId
            Dim StartDate As String = myRepTable.StartDate
            Dim EndDate As String = myRepTable.EndDate
            For j As Integer = 0 To myRepTable.Resource(i).Weeks.Length - 1
                Dim WeekNumber As Integer = myRepTable.Resource(i).Weeks(j).WeekNumber
                Dim Hours As Decimal = myRepTable.Resource(i).Weeks(j).Hours
4

1 に答える 1

0

OK、これを解決する簡単な方法を見つけました。

Visual Studio 2012 には、XSD Schema to Serialization コーディング ツールがあります。

Infopath で、フォームをソースとして保存します (ファイル メニューから)。

次に、[スタート] --> [Visual Studio] --> [Visual Studio ツール] --> [開発者コマンド プロンプト] に移動します。infpath ソースを保存したディレクトリに移動し、次のように入力します。

xsd myschema.xsd /classes

私も追加しました

/language:VB

その後、VB コードを取得します。コードが正しい形式で同じフォルダーに保存されます。自分で書くよりずっと簡単です。

于 2013-08-21T18:57:00.127 に答える