|
本帖最后由 tsp_1030 于 2014-5-2 18:17 编辑
Lazarus由于没有集成webservice,所以如果想用Webservice必须安装第三方Web Service Toolkit来使用,但是使用起来很不方便,也有版本不兼容的问题。通过自己的摸索现在总结了一套简单高效的方法,灵感是来自http协议,因为webservice是通过soap协议通讯的,而soap协议本属于http的一种封装协议,所以知道soap的协议格式就可以了,废话不说了,具体看如下:
1.首先得有网络通讯控件,我用了lnet的httpclient,lnet有个好处是可以兼容wince。(lent控件源代码里有httpclient的demo,可以参考使用)
2.请求调用wenservice的关键代码:
EditURL.Text:='http://222.175.191.186:8888/zceam/services/Datalist'; HTTPBuffer := '';
SSL.SSLActive := DecomposeURL(EditURL.Text, aHost, aURI, aPort);
HTTPClient.Host := aHost;
HTTPClient.URI := aURI;
HTTPClient.Port := aPort;
HTTPClient.Method:=hmPost;
Fstr:='<?xml version="1.0" encoding="utf-8"?>';
Fstr:=Fstr+'<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/">';
Fstr:=Fstr+'<soap:Body>';
Fstr:=Fstr+'<GetRyxx xmlns="http://webservice.bjzc.com">'; //通过?wsdl查看信息targetNamespace="http://webservice.bjzc.com">
//Fstr:=Fstr+'<userID>string</userID>'; //参数
Fstr:=Fstr+'</GetRyxx>';
Fstr:=Fstr+'</soap:Body>';
Fstr:=Fstr+'</soap:Envelope>';
Fstr:=Fstr+'';
Fstr:=Fstr+'';
Fstr:=Fstr+'';
headln:=0;dataln:=length(Fstr);
httpclient.AddExtraHeader('Keep-Alive: 300');
httpclient.AddExtraHeader('Connection: keep-alive');
httpclient.AddExtraHeader('Content-Length: '+inttostr(headln+dataln));
httpclient.AddExtraHeader('Content-Type: xml;'); /////// multipart/form-data ////stream
//httpclient.AddExtraHeader('SOAPAction: "http://222.175.191.186:8888/zceam/services/GetgwList"'); //通过?wsdl查看信息soapAction
httpclient.AddExtraHeader(LineEnding+Fstr);
HTTPClient.SendRequest;
3.接收数据参考lent里面的httpclient的例子。
|
评分
-
查看全部评分
|