使用第三方wsdl将xml记录作为soap消息传递 [英] Passing xml record as a soap message using 3rd party wsdl

查看:46
本文介绍了使用第三方wsdl将xml记录作为soap消息传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个包含大量记录的xml文件,该文件被读入并进入foreach循环读取每条记录一时间从这里我想通过提供给我的第三方wsdl传递它。



我的代码在下面,我肯定必须有一个更简单的方法要做到这一点。



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.

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("-----------------------------------------------------------------------------");
                       }
               }





单个xml记录是:





A singe xml record is:

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



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

Any help would be greatly appreciated.

推荐答案

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[^]
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[^]


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.



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


这篇关于使用第三方wsdl将xml记录作为soap消息传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆