在delphi7里如何调用webservice服务,在线等待..急

yangzong19 2011-03-31 11:04:32
我用WSDL生成了一个单元然后uses到from1里了,但我调用里面的GetServerTime和UpBroke函数的时候总是出错,麻烦各位大哥帮小弟看看,小弟万分感谢!


这是用WSDL生成的SOAP但源代码

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://127.0.0.1:9000/SOAP?service=nnmzd_Service
// Encoding : UTF-8
// Version : 1.0
// (2011-3-31 10:55:22 - 1.33.2.5)
// ************************************************************************ //

unit SOAP;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

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.
// ************************************************************************ //
// !:int - "http://www.w3.org/2001/XMLSchema"
// !:dateTime - "http://www.w3.org/2001/XMLSchema"
// !:base64Binary - "http://www.w3.org/2001/XMLSchema"



// ************************************************************************ //
// Namespace : http://tempuri.org/
// soapAction: urn:nnmzd_Library-nnmzd_Service#%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : nnmzd_ServiceBinding
// service : nnmzd_Service
// port : nnmzd_ServicePort
// URL : http://127.0.0.1:9000/SOAP?service=nnmzd_Service
// ************************************************************************ //
nnmzd_Service = interface(IInvokable)
['{984A1501-F6A3-D06A-AAE3-F01206265B3C}']
function Sum(const A: Integer; const B: Integer): Integer; stdcall;
function GetServerTime: TXSDateTime; stdcall;
function UpBroke(const Data: TByteDynArray): Integer; stdcall;
end;

function Getnnmzd_Service(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): nnmzd_Service;


implementation

function Getnnmzd_Service(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): nnmzd_Service;
const
defWSDL = 'http://127.0.0.1:9000/SOAP?service=nnmzd_Service';
defURL = 'http://127.0.0.1:9000/SOAP?service=nnmzd_Service';
defSvc = 'nnmzd_Service';
defPrt = 'nnmzd_ServicePort';
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 nnmzd_Service);
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(nnmzd_Service), 'http://tempuri.org/', 'UTF-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(nnmzd_Service), 'urn:nnmzd_Library-nnmzd_Service#%operationName%');

end.





这是from1代码

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses SOAP;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
server1:nnmzd_Service;
aa:string;
begin
aa:=datetostr(server1.GetServerTime); //在这里我想调用 function GetServerTime: TXSDateTime; stdcall;这个函数

//在这里我想掉用function UpBroke(const Data: TByteDynArray): Integer; stdcall; 这个函数
end;

end.


麻烦大哥们帮小弟看看,小弟跪谢了
...全文
375 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
solonet 2011-06-23
  • 打赏
  • 举报
回复
关注一下,楼主现在解决这个问题了没有?
如果解决了,请公布一下,方便 大家 学习。
yangzong19 2011-03-31
  • 打赏
  • 举报
回复
to notebook800
就是这个地址呀
http://127.0.0.1:9000/SOAP?service=nnmzd_Service
notebook800 2011-03-31
  • 打赏
  • 举报
回复
用浏览器测试你的webservice的wsdl
lcmlhs_2005 2011-03-31
  • 打赏
  • 举报
回复
友情一顶,帮你顶,学习一下
yangzong27 2011-03-31
  • 打赏
  • 举报
回复
to wgxis
不行呀
wgxis 2011-03-31
  • 打赏
  • 举报
回复
生成SOAP的Getnnmzd_Service函数尾加上试试


RIO.HTTPWebNode.UseUTF8InHeader := true; //添加该行,指定采用UTF-8代码传输
RIO.Converter.Encoding:='UTF-8';
RIO.Converter.Options:=RIO.Converter.Options + [soUTF8InHeader,soUTF8EncodeXML];

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧