Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have an xml file with a number of records in it, the file is read in and goes into a foreach loop reading each record at a time. from here I want to pass it using the 3rd party wsdl that was supplied to me.

My code is below and I'm sure there must be an easier way to do this.

C#
foreach (var record in nodes)
               {
                   // Increment record count
                   countNumberOfRecords += 1;
                   // Get value of object reference
                   string objref = record.Element("BriefDetails").Element("ObjectID").Element("ObjectReference").Value;
                   string objID = record.Element("BriefDetails").Element("ObjectID").Element("ObjectType").Value;
                   // Build up soap message
                   foreach (var element in record.Elements("BriefDetails").Elements("ObjectID"))
                   {
                       //inUpdate.BriefDetails = new FWTObjectID[]
                       {
                           //briefDetails.ObjectType = record.Elements("ObjectType").ToString();
                           //briefDetails.ObjectReference = objref;
                       };
                   }
                   foreach (var element in record.Elements("Name").Elements("IndividualNameDetails"))
                   {
                       inUpdate.Name = new FWTIndividualNameUpdate[]
                       {
                          individualNameUpdateDetails

                       };
                   }
                   foreach (var element in record.Elements("ContactPostals").Elements("PostalDetails"))
                   {
                       inUpdate.ContactPostals = new FWTContactPostalUpdate[]
                       {
                           contactUpdate
                       };
                   }
                   foreach (var element in record.Elements("ContactPhones").Elements("PhoneDetails"))
                   {
                       inUpdate.ContactPhones = new FWTContactPhoneUpdate[]
                       {
                           phoneUpdate
                       };
                   }
                   foreach (var element in record.Elements("ContactEmails").Elements("EmailDetails"))
                   {
                       inUpdate.ContactEmails = new FWTContactEmailUpdate[]
                       {
                           emailUpdate
                       };
                   }

                   foreach (var element in record.Elements("GenderUpdate"))
                   {
                       inUpdate.GenderUpdate = new FWTGenderUpdate();
                       {
                           genderUpdate.ToString();
                       }
                   }
                   foreach (var element in record.Elements("NationalityUpdate"))
                   {
                       inUpdate.NationalityUpdate = new FWTNationalityUpdate();
                       {
                           nationalityUpdate.ToString();
                       }
                   }
                   //foreach (var element in record.Elements("NationalInsuranceNumberUpdate"))
                   //{
                   //    inUpdate.NationalInsuranceNumberUpdate = new FWTNationalInsuranceNumberUpdate();
                   //    {
                   //        nationalInsuranceNumberUpdate.ToString;
                   //    }
                   //}
                   //foreach (var element in record.Elements("EthnicityUpdate"))
                   //{
                   //    inUpdate.EthnicityUpdate = new FWTEthnicityUpdate();
                   //    {
                   //        ethnicityUpdate.ToString;
                   //    }
                   //}
                   //foreach (var element in record.Elements("DisabilitiesUpdate"))
                   //{
                   //    inUpdate.DisabilitiesUpdate = new FWTDisabilitiesUpdate();
                   //    {
                   //        disabilityUpdate.ToString;
                   //    }
                   //}
                   foreach (var element in record.Elements("DateOfBirthUpdate"))
                   {
                       inUpdate.DateOfBirthUpdate = new FWTDateOfBirthUpdate();
                       {
                           dateOfBirthUpdate.ToString();
                       }
                   }
                   foreach (var element in record.Elements("PreferredLanguageUpdate"))
                   {
                       inUpdate.PreferredLanguageUpdate = new FWTPreferredLanguageUpdate();
                       {
                           preferredLanguageUpdate.ToString();
                       }
                   }
                   foreach (var element in record.Elements("UserDefinedUpdate"))
                   {
                       inUpdate.UserDefinedUpdate = new FWTUserDefinedUpdate[]
                       {
                           userDefinedUpdate
                       };
                   }
                   foreach (var element in record.Elements("UserDefinedNumUpdate"))
                   {
                       inUpdate.UserDefinedNumUpdate = new FWTUserDefinedNumUpdate[]
                       {
                           userDefinedNumberUpdate
                       };
                   }
                   foreach (var element in record.Elements("UserDefinedTextUpdate"))
                   {
                       inUpdate.UserDefinedTextUpdate = new FWTUserDefinedTextUpdate[]
                       {
                           userDefinedTextUpdate
                       };
                   }
                   // Update record
                       try
                       {
                           Console.WriteLine("Attempting update individual");
                           Console.WriteLine("-----------------------------------------------------------------------------");
                          // *** Problem here trying to invoke the update individual method *****
                           int result = laganFLWebServices.updateIndividual(inUpdate);
                          //int result = laganFLWebServices.updateIndividual(inUpdate);
                           Console.WriteLine("Record Number " + countNumberOfRecords);
                           Console.WriteLine(objref + " Updated successfully!");
                           Console.WriteLine("-----------------------------------------------------------------------------");
                       }
                       catch (Exception ex)
                       {
                           //Obviously this would need more robust error handling
                           Console.WriteLine("EXCEPTION CAUGHT Update failed!");
                           HandleException(ex);
                           Console.WriteLine("-----------------------------------------------------------------------------");
                       }
               }


A singe xml record is:

XML
<<DATA_RECORD>
- <           <EXTRACT>
- <                     <FWTIndividualUpdate>
- <                              <BriefDetails>
- <                                        <ObjectID>
  <                                                  <ObjectType>C1</ObjectType> 
  <                                                  <ObjectReference>101006321370</ObjectReference> 
                                         </ObjectID>
                               </BriefDetails>
- <                                      <Name>
- <                                                  <IndividualNameDetails>
  <                                                              <Title>Mrs</Title> 
  <                                                              <Forename>M</Forename> 
  <                                                              <Initials>M</Initials> 
  <                                                              <Surname>Crich</Surname> 
  <                                                              <FullName>Mrs M Crich</FullName> 
  <                                                              <Preferred>true</Preferred> 
                                                   </IndividualNameDetails>
                                       </Name>
- <                              <ContactPostals>
- <                                        <PostalDetails>
  <                                                  <AddressNumber>30</AddressNumber> 
- <                                                  <AddressLine>
  <                                                           <string>Merlay Hall</string> 
  <                                                            <string>Greenford Road</string> 
  <                                                           <string>Newcastle Upon Tyne</string> 
  <                                                           <string /> 
  <                                                           <string /> 
                                                   </AddressLine>
  <                                                  <Postcode>NE6 3XE</Postcode> 
                                               <UPRN>4510121987</UPRN> 
- <                                                  <UserDefined>
  <                                                           <string /> 
  <                                                           <string /> 
  <                                                           <string /> 
  <                                                           <string /> 
  <                                                           <string /> 
  <                                                           <string /> 
  <                                                           <string /> 
  <                                                           <string>SECURE</string> 
                                                   </UserDefined>
- <                                                  <UserDefinedNum>
  <                                                           <long>63427</long> 
  <                                                           <long>37969</long> 
                                                   </UserDefinedNum>
- <                                                  <UserDefinedText>
  <                                                           <string>HRA_WA02</string> 
  <                                                           <string>Ms Ruth Crawford</string> 
                                                   </UserDefinedText>
- <                                                  <UserDefinedDate>
  <                                                           <date>2001-01-15</date> 
                                                   </UserDefinedDate>
                                         </PostalDetails>
                                </ContactPostals>
- <                               <ContactPhones>
- <                                        <PhoneDetails>
  <                                                  <Number /> 
  <                                                  <DeviceType /> 
  <                                                 <Usage>Unknown</Usage> 
                                        </PhoneDetails>
- <                                        <PhoneDetails>
  <                                                  <Number /> 
  <                                                  <DeviceType /> 
  <                                                  <Usage>Unknown</Usage> 
                                         </PhoneDetails>
- <                                        <PhoneDetails>
  <                                                  <Number /> 
  <                                                  <DeviceType /> 
  <                                                  <Usage>Unknown</Usage> 
                                         </PhoneDetails>
- <                                        <PhoneDetails>
  <                                                  <Number /> 
  <                                                  <DeviceType /> 
  <                                                  <Usage>Unknown</Usage> 
                                         </PhoneDetails>
                               </ContactPhones>
- <                              <ContactEmails>
- <                                        <EmailDetails>
  <                                                  <EmailAddress /> 
  <                                                  <Usage>Unknown</Usage> 
                                         </EmailDetails>
                               </ContactEmails>
- <                                      <GenderUpdate>
  <                                                  <Gender>F</Gender> 
                                       </GenderUpdate>
- <                              <NationalityUpdate>
  <                                        <Nationality /> 
                               </NationalityUpdate>
- <                              <MaritalStatusUpdate>
  <                                        <MaritalStatus /> 
                               </MaritalStatusUpdate>
- <                              <NationalInsuranceNumberUpdate>
  <                                        <NationalInsuranceNumber>CC445566B</NationalInsuranceNumber> 
                               </NationalInsuranceNumberUpdate>
- <                              <EthnicityUpdate>
  <                                        <Ethnicity>WI</Ethnicity> 
                               </EthnicityUpdate>
- <                              <DisabilitiesUpdate>
  <                                        <Disabilities>Y</Disabilities> 
                               </DisabilitiesUpdate>
- <                              <DateOfBirthUpdate>
  <                                        <DateOfBirth>1951-04-25</DateOfBirth> 
                               </DateOfBirthUpdate>
- <                              <PreferredLanguageUpdate>
  <                                        <PreferredLanguage>EN</PreferredLanguage> 
                               </PreferredLanguageUpdate>
- <                              <UserDefined>
  <                                        <string /> 
  <                                        <string /> 
  <                                        <string /> 
  <                                        <string /> 
  <                                        <string>NORTHGATE</string> 
                               </UserDefined>
- <                              <UserDefinedNum>
  <                                        <long>0</long> 
  <                                        <long>0</long> 
  <                                        <long>0</long> 
  <                                        <long>0</long> 
  <                                        <long>0</long> 
  <                                        <long>38081</long> 
                               </UserDefinedNum>
- <                              <UserDefinedText>
  <                                        <string /> 
  <                                        <string>DNS</string> 
  <                                        <string /> 
  <                                        <string /> 
  <                                        <string /> 
  <                                        <string /> 
  <                                        <string /> 
                               </UserDefinedText>
                      </FWTIndividualUpdate>
            </EXTRACT>
  </DATA_RECORD>


I am using a consol app as we need to see the authentication dteails etc.

Any help would be greatly appreciated.
Posted

You need to add the wsdl as a web reference (or use svcUtil) to your project.
This will generate a proxy class that you can populate using your objects.

In this way, you will not need to create any xml.

For further information -
http://chakkaradeep.wordpress.com/2008/08/07/generating-wcf-proxy-using-svcutilexe/[^]
http://en.csharp-online.net/WCF_Essentials%E2%80%94Generating_the_Proxy[^]
 
Share this answer
 
Hi,

I already have done that, the xml is created from a script from a database and the code is to update a record in another database hence the reason I need to read it in one record ata time.

Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900