ImageVerifierCode 换一换
格式:DOCX , 页数:11 ,大小:110.60KB ,
资源ID:21449562      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/21449562.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Delphi调用Webservice的例子Word文件下载.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Delphi调用Webservice的例子Word文件下载.docx

1、Ive created a sample form , which looks like this:Now weve setup the HTTPRio, and the code behind the Get Zip Codes button is: procedure TForm1.Button1Click(Sender: TObject);begin(HTTPRIO1 as ZipCodesSoap).rtnZipDS(edtCity.Text, edtState.Text);ve also added an event handler on the HTTPRio1.OnAfterEx

2、ecute like so:procedure TForm1.HTTPRIO1AfterExecute(const MethodName:SOAPResponse: TStream);SOAPResponse.Position := 0;Memo1.Lines.LoadFromStream(SOAPResponse);This is only to display the returned content on to a Memo so we can figure out what to do with it. Heres how the form looks now:Interpreting

3、 the .NET XML We have to figure out how to get Delphi to USE this data. We would like to have a Client Data Set read the XML so we can display it all in a Grid. For that well have to use XDR transforms. No, thats not very complicated, and heres how well do it. 1. First were going to save the XML ret

4、urned into an XML file. Ive saved it as data.xml.2. Run XML mapper from the Tools menu, and open this XML file. Heres a mega screen shot:3. The ZIPDATA(*) means theres multiple rows of ZIPDATA available. Columns availabl are Zip, City, State, County and AreaCode. Lets double-click each one of these

5、to add them to the transformation and then click the DataPacket from XML in the Create Menu. Heres what it all looks like:4. Save the Transformation using File | Save | Transformation, as Ziptrans.xtr. Dont try to test the transformation yet. (Theres a bug in Delphi Source code that doesnt like SOAP

6、 namespaces in certain elements so it doesnt show up any data). 5. Well now FIX this bug. The XTR file is an XML file which you can open in any text editor. Open it, and change the first line from:Change ToEnvelopesoap:The reason for this is that Delphis XML Transform provider does not like the soap

7、: in the first element of the from attribute. That might get fixed in some update pack, so this point might not apply 6. Were nearly there. Drop a TClientDataset, a TXMLTransformProvider and a TDatasource on the form. Heres what the form looks like now:Link the Grid, the Datasource and the ClientDat

8、aset, and set the ClientDatasets ProviderName to point to the XML Transform Provider. 7. Set the TransformRead.TransformationFile of the XMLTransformProvider to Ziptrans.XTR. 8. Now we need to set the data of the XML Transform Provider at run time. Heres some additional code in the HTTPRios OnAfterE

9、xecute:varXMLDoc: IXMLDocument;ClientDataset1.Active := FALSE;XMLDoc := NewXMLDocument;XMLDoc.Encoding := SUTF8;XMLDoc.LoadFromStream(SOAPResponse);XMLTransformProvider1.TransformRead.SourceXmlDocument := XMLDoc.GetDOMDocument;= TRUE;Youll notice that weve created an XML Document , loaded it from th

10、e Received SOAP stream, and applied the transform to it. The client dataset gets data from the provider and displays the data :Thats it!Amazing.Thank you. Whats next?This transformation is very specific to this particular service and XML schema. SO if you know what XML is going to be returned (the f

11、ormat) then you can use XML mapper to generate a transformation for it. I havent been able to write a general transform that can be applied to ANY .NET returned XML, but if anyone does Id love to hear about it. Also, why have I used the HTTPRios OnAfterExecute, rather than manipulating the the s_sch

12、ema parameter? Theres another bug in Delphi that doesnt like parameters returned as XML. More revealed in this thread. You can download all the code for this project at or at Deepak Shenoy(shenoy) is a Director at Agni Software, a software company in India that offers consultancy and offshore develo

13、pment solutions. It might be a while before his hair gets pointy so hes allowed to understand some technology. 在微软中国找到了一个官方的说法-不建议将DataSet直接作为返回值传送,因为里面含有大量复杂的schema以及更改等信息,大部分非.NET语言在解析上有困难。建议使用DataSet.WriteXML方法将简化后的XML版本作为一个WideString回传。经过试验,已经在Delphi下轻松通过,Delphi中还需要使用XML Mapper工具事先生成Transfomatio

14、n(XTR)文件。Delphi7客户端代码 - unit WSTestMain;interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, InvokeRegistry, StdCtrls, Rio, SOAPHTTPClient, Grids, DBGrids, DB, DBClient, DBTables, Provider, xmldom, Xmlxform,XMLIntf,XMLDoc,SOAPConst;type TForm1 = class(TF

15、orm) HTTPRIO1: THTTPRIO;Button1: TButton;Memo1: TMemo;XMLTransformProvider1: TXMLTransformProvider;ClientDataSet1: TClientDataSet;DataSource1: TDataSource;DBGrid1: TDBGrid;procedure Button1Click(Sender:private Private declarations public Public declarations var Form1: TForm1;implementation uses WSTe

16、stDefine;$R *.dfm A:Service1Soap;B:WideString;begin A := HTTPRIO1 as Service1Soap;B := A.GetPersonTable;Memo1.Lines.Add( B );XMLDoc.LoadFromXML(B);end. - .NET WebService代码 System.Text.StringBuilder strbuilder=new System.Text.StringBuilder();StringWriter writer=new StringWriter(strbuilder);dataset.Wr

17、iteXml(writer,System.Data.XmlWriteMode.IgnoreSchema);return strbuilder.ToString();class XmlDatasetConvert/将xml对象内容字符串转换为DataSetpublic static DataSet ConvertXMLToDataSet(string xmlData)StringReader stream = null;XmlTextReader reader = null;tryDataSet xmlDS = new DataSet();stream = new StringReader(xm

18、lData);/从stream装载到XmlTextReaderreader = new XmlTextReader(stream);xmlDS.ReadXml(reader);return xmlDS;catch (System.Exception ex)throw ex;finallyif (reader != null)reader.Close();/将xml文件转换为DataSetpublic static DataSet ConvertXMLFileToDataSet(string xmlFile)XmlDocument xmld = new XmlDocument();xmld.Lo

19、ad(xmlFile);stream = new StringReader(xmld.InnerXml);/xmlDS.ReadXml(xmlFile);/将DataSet转换为xml对象字符串public static string ConvertDataSetToXML(DataSet xmlDS)MemoryStream stream = null;XmlTextWriter writer = null;stream = new MemoryStream();writer = new XmlTextWriter(stream, Encoding.Unicode);/用WriteXml方法

20、写入文件.xmlDS.WriteXml(writer);int count = (int) stream.Length;byte arr = new bytecount;stream.Seek(0, SeekOrigin.Begin);stream.Read(arr, 0, count);UnicodeEncoding utf = new UnicodeEncoding();return utf.GetString(arr).Trim();if (writer !writer.Close();/将DataSet转换为xml文件public static void ConvertDataSetToXMLFile(DataSet xmlDS, string xmlFile)/返回Unicode编码的文本StreamWriter sw = new StreamWriter(xmlFile);sw.WriteLine(?xml version=1.0 encoding=utf-8);sw.WriteLine(utf.GetString(arr).Trim();sw.Close();

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1