vb.net - Submitting Infopath repeating table data to SQL using Web Service -


this first time using xml serialization , i'm not sure if can submit nested repeating tables, or how serialize arrays within arrays.

i have infopath form "weeks" repeating table within "resource" repeating table. xml output:

<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> 

i trying serialize asmx web service writing sql database. can working 1 repeating table, when try , place second 1 inside i'm not getting data through. repeatingtable class serialization:

<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 resource() public requestid integer public startdate date public enddate date  end class     public class resource     public person person()     public weeks weeks() end class  public class weeks     public weeknumber integer     public hours decimal end class  public class person     public displayname string     public accountid string     public accounttype string end class 

my web service soap evelope looks this, notice person , weeks nodes don't inclide child nodes:

<?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> 

this webservice code:

 public sub submitrepeatingtable(myreptable repeatingtable)          dim myconnection sqlconnection = new sqlconnection()         myconnection = new sqlconnection(connectionstring)         myconnection.open()         dim command new sqlclient.sqlcommand("usp_add_allocation")         command.commandtype = commandtype.storedprocedure         command.connection = myconnection          integer = 0 myreptable.resource.length - 1             dim requestid integer = myreptable.requestid             dim accountid string = myreptable.resource(i).person(i).accountid             dim startdate string = myreptable.startdate             dim enddate string = myreptable.enddate             j integer = 0 myreptable.resource(i).weeks.length - 1                 dim weeknumber integer = myreptable.resource(i).weeks(j).weeknumber                 dim hours decimal = myreptable.resource(i).weeks(j).hours 

ok, figured out simple way solve this:

visual studio 2012 has xsd schema serialization coding tool.

in infopath, save form source (from file menu).

then go start --> visual studio --> visual studio tools --> developer command prompt. navigate directory saved infpath source , type:

xsd myschema.xsd /classes 

i added

/language:vb 

afterwards vb code. save code same folder in correct format. easier writing myself.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -