关于WEBSERVICE服务调用的问题

heihei19811222 2010-05-21 10:55:14
我写了个WEBSERVICE,并发布在远程服务器上,里面的接口主要是用来取和写远程服务器上的数据库内容,现在有个情况就是,客户端都是内网的,无法连接WEBSERVICE服务,所以我打算在内网服务器上再发布个同样接口的WEBSERVICE,利用这个内望发布的服务函数去调用远端发布的服务函数,我不知道这样是否可行,因为我也是新手



但测试后发现内望发布的WEBSERVCE在调用远端发布的服务的时候总是报错:

vWSObj := CreateOleObject('MSSOAP.SoapClient');
vWSObj.mssoapinit('http://xx.xx.xx.x/DataSynch/Ds.dll/wsdl/IDataSynch');
try
try
vWSObj.HandShake;
except
Result := 1;
end;
finally
vWSObj := Unassigned;
end;


在创建CreateOleObject('MSSOAP.SoapClient');时总是报,错误类型的字符串,我已经引用了COMOBJ

而且我单独在EXE里调用远端服务又都是OK的,随知道为什么?
...全文
108 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
寻_风 2011-01-06
  • 打赏
  • 举报
回复
我觉得你这个关键不是怎么调用的问题,而是网络问题,如果你的内网能访问到远程webservice服务就OK了,就类似4楼代码里的“defURL = 'http://172.20.100.10/test/service.asmx'”,能访问到,就能调用。
gwhdaxia 2010-07-26
  • 打赏
  • 举报
回复
我前段时间尝试过java做的webservice调用jave的webservice,是没问题的
kye_jufei 2010-07-26
  • 打赏
  • 举报
回复
調用:

unit Unit1;

interface

uses
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.
kye_jufei 2010-07-26
  • 打赏
  • 举报
回复
給個demo供參考:

// ************************************************************************ //
// 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;

interface

uses 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.
heihei19811222 2010-05-22
  • 打赏
  • 举报
回复
没人知道么?不会吧?自己顶
hanks_gao 2010-05-22
  • 打赏
  • 举报
回复
用THTTPRIO控件調用下試試!

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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