关于WEBService接口的问题?
大家好,首先本人对web service不太了解,现在做一个项目,其中要做一个员工资料的同步程序。
对方是一个ORACLE数据库的HR系统,我这边的程序需要调用它的人员资料,但是它HR系统不允许我直接访问ORACLE数据库里的表数据,只是一个WEBSERVICE接口给到我,我想问一下,这个所谓的接口是一个什么样的东西,是一系列的函数说明吗?我用DELPHI能直接调用它提供的WEBSERVICE接口吗?
[解决办法]
Web Service似DLL,它提供一系列、值型等接口,你入些值,它去索後最得到你想要的果,以下我你提供一例子:
- Delphi(Pascal) code
// ************************************************************************ //// The types declared in this file were generated from data read from the// WSDL File described below:// WSDL : http://172.20.100.10/test/service.asmx?wsdl// >Import : http://172.20.100.10/test/service.asmx?wsdl:0// Encoding : utf-8// Version : 1.0// (2010/6/22 上午 11:31:35 - - $Rev: 10138 $)// ************************************************************************ //unit service;interfaceuses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;const IS_OPTN = $0001; IS_REF = $0080;type // ************************************************************************ // // The following types, referred to in the WSDL document are not being represented // in this file. They are either aliases[@] of other types represented or were referred // to but never[!] declared in the document. The types from the latter category // typically map to predefined/known XML or Borland types; however, they could also // indicate incorrect WSDL documents that failed to declare or import a schema type. // ************************************************************************ // // !:string - "http://www.w3.org/2001/XMLSchema"[Gbl] // ************************************************************************ // // Namespace : Kye // soapAction: Kye/HelloWorld // transport : http://schemas.xmlsoap.org/soap/http // style : document // binding : ServiceSoap // service : Service // port : ServiceSoap // URL : http://172.20.100.10/test/service.asmx // ************************************************************************ // ServiceSoap = interface(IInvokable) ['{B82FAFBA-EAB8-AD5C-2535-FB6046355616}'] function HelloWorld(const name_: WideString): WideString; stdcall; end;function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ServiceSoap;implementation uses SysUtils;function GetServiceSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): ServiceSoap;const defWSDL = 'http://172.20.100.10/test/service.asmx?wsdl'; defURL = 'http://172.20.100.10/test/service.asmx'; defSvc = 'Service'; defPrt = 'ServiceSoap';var RIO: THTTPRIO;begin Result := nil; if (Addr = '') then begin if UseWSDL then Addr := defWSDL else Addr := defURL; end; if HTTPRIO = nil then RIO := THTTPRIO.Create(nil) else RIO := HTTPRIO; try Result := (RIO as ServiceSoap); if UseWSDL then begin RIO.WSDLLocation := Addr; RIO.Service := defSvc; RIO.Port := defPrt; end else RIO.URL := Addr; finally if (Result = nil) and (HTTPRIO = nil) then RIO.Free; end;end;initialization InvRegistry.RegisterInterface(TypeInfo(ServiceSoap), 'Kye', 'utf-8'); InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceSoap), 'Kye/HelloWorld'); InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument); InvRegistry.RegisterExternalParamName(TypeInfo(ServiceSoap), 'HelloWorld', 'name_', 'name');end.
[解决办法]
用:
- Delphi(Pascal) code
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,service, StdCtrls;type TForm1 = class(TForm) btn1: TButton; edt1: TEdit; Label1: TLabel; procedure btn1Click(Sender: TObject); private aa:ServiceSoap; { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btn1Click(Sender: TObject);begin aa:=GetServiceSoap(False,'',nil); ShowMessage(aa.HelloWorld(edt1.Text));end;end.
[解决办法]
记得delphi 有一个 HTTPRIO 控件,在WebService选项卡下,可以把webservices提供的接口转换化为delphi的函数,然后你再你的程序中,指把它当成普通的函数调用就可以了。
不过,不建议这样用,这样有很多限制的,再者参数类型稍微复杂一点恐怕就不行了。
你可以用原生的 idhttp 发送数据包,这样更灵活
[解决办法]
是的,webservices提供的接口转换化为delphi的函数,然后你再你的程序中,指把它当成普通的函数调用就可以了~~~其方法如下(MS-DOC方式也可出pas文件):
file->New->webservice->WSDL Import Wizard框(WSDL Source)或入你的webservice地址即可生delphi的pas文件,再向我之前的demo用即可。。。
[解决办法]
直接用CBX框架,就能解决问题
=================================
CBX框架是一套健壮、简单易用的Delphi三层框架,完全以Midas为基础行开发,非常适合开发大型企业应用。CBX是一个完备的体现RIA思想的应用开发框架,它充分的具备了这三大要素,包含:浏览器ao运行容器插件;宿主在IIS的应用服务器兼部署服务器;以Delphi 7为基础扩展而来的强大开发环境。
CBX的价值在于:
能够将Delphi7开发桌面应用的强大能力搬上了浏览器,远远超越基于Html乃至Ajax技术的Web开发技术的能力范畴,它意味着:几乎所有的VCL控件都能直接用使用在Web客户端中;几乎所有的Windows API都可以在客户端调用;客户端代码执行效率达到了C++的级别; 能使用客户端电脑的所有硬件资源。
具备一个简约而高效强大的服务器容器环境,能够用Delphi Midas的开发模式开发高效率的、能够穿透防火墙、在互联网上运行的应用服务器,天然集成无状态中间层业务对象的机制,系统层次简捷健壮,充分体现了三层构架的高性能,将三层构架系统的特性发挥到了极致;
CBX具备高度开放的访问接口,天然面向和各种Web系统交互和集成,诸如:JSP、ASP、ASP.Net、PHP乃至静态html网页,开发者不仅可以将CBX模块自如的嵌入到纯Web系统中,而且还能通过灵活的接口和CBX对象交互,让CBX充当各种纯Web构架方案的强有力补充,弥补纯html技术能力所不能及之处。
请加入500人超级CBX&Delphi群 11701114
[解决办法]
生成的时候路径后面加?wsdl了吗,如果没有函数那就是他们接口的问题了吧
[解决办法]
如果你定生成PAS文件(要加?WSDL)一函明;那再定一下抓XML包什也有;那可以定他的service接口有,快解此,便把了...