SOAP Response Packet: result element expected, received "<ConfrimResponse xmlns="http://tempuri.org/"/>"WebService应该没问题,用C#调完全正常,而且用Delphi调,不需要string参数的函数都没问题,返回类型是string也没问题。D6是古董了点,但暂时不能动,请高手们提供个解决方法。
解决方案 »
- 一个delphi7中窗体间传递的奇怪问题
- delphi中画网络线
- 我什么时候才能用上无风扇的电脑?
- 急急,,,在家幫我看看這些代碼是什么意思...
- 请问,polypolygon函数怎么使用啊
- 关于CORBA程序的接口(IDL文件)编译问题,高手请帮忙!
- 如何调整bmp图形亮度,答得好的有50分
- 关于分析网页源码, 目的是要取出网页源码中的相关信息, 目前不知该用何种方法取,正则表达式? 还是什么? 请大家进来说说,谢谢
- 请问哪时有Delphi6.0下载?
- 如何判断数据库中的NULL字段
- 如何实现进度条,显示%比,并显示下载速度,下载剩余时间.....delphi中
- Delphi 7 简单问题希望高手帮助
String是第一位是字符串的长度,从第二位开始才是真正的数据
var
saa:ServiceSoap;
str:widestring;
begin
str := widestring('abc');
saa := GetServiceSoap();
edit1.Text := saa.Confirm(str);
end;这样写对吗?
unit version;interfaceuses 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.
// ************************************************************************ //
// !:string - "http://www.w3.org/2001/XMLSchema" // ************************************************************************ //
// Namespace : http://csyangpeng.cn/
// soapAction: http://csyangpeng.cn/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : VersionSoap
// service : Version
// port : VersionSoap
// URL : http://www.MyService.com/services/version.asmx
// ************************************************************************ //
VersionSoap = interface(IInvokable)
['{B274BBBB-F68D-7338-454D-6E33B840DEBE}']
function GetDataURL: WideString; stdcall;
function GetSSJKURL: WideString; stdcall;
function GetVersion: WideString; stdcall;
function GetDataVersion: WideString; stdcall;
procedure SetDataVersion; stdcall;
end;function GetVersionSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): VersionSoap;
implementationuses UniMain;function GetVersionSoap(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): VersionSoap;
const
defSvc = 'Version';
defPrt = 'VersionSoap';
var
RIO: THTTPRIO;
begin
Result := nil;
if (Addr = '') then
begin
if UseWSDL then
//Addr := defWSDL
Addr := MainForm.edtWebService.Text+'?wsdl'
else
//Addr := defURL;
Addr := MainForm.edtWebService.Text;
end;
if HTTPRIO = nil then
RIO := THTTPRIO.Create(nil)
else
RIO := HTTPRIO;
try
Result := (RIO as VersionSoap);
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(VersionSoap), 'http://csyangpeng.cn/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(VersionSoap), 'http://csyangpeng.cn/%operationName%');end.
在主程序中引用:uses version;
然后: Label11.Caption:= '当前版本号:'+GetVersionSoap.GetDataVersion;
就OK了。
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://10.16.66.16/KiTest/service.asmx?wsdl
// Encoding : utf-8
// Version : 1.0
// (2008-04-09 13:00:12 - $Revision: 1.9.1.0.1.0.1.9 $)
// ************************************************************************ //
unit service;
interface
uses InvokeRegistry, 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.
// ************************************************************************ //
// !:string - "http://www.w3.org/2001/XMLSchema"
// !:int - "http://www.w3.org/2001/XMLSchema"
// !:string - "http://tempuri.org/"
ArrayOfString = array of String; { "http://tempuri.org/" }
// ************************************************************************ //
// Namespace : http://tempuri.org/
// soapAction: http://tempuri.org/%operationName%
// transport : http://schemas.xmlsoap.org/soap/http
// binding : ServiceSoap
// service : Service
// port : ServiceSoap
// URL : http://10.16.66.16/KiTest/service.asmx
// ************************************************************************ //
ServiceSoap = interface(IInvokable)
['{77573149-9C57-FA51-F11F-EFD527C91BD9}']
function HelloWorld: String; stdcall;
function GetBarCode(const index: Integer; const data: ArrayOfString): String; stdcall;
function Confirm(const s: string): string; stdcall;
end;
function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''): ServiceSoap;implementation
uses SOAPHTTPClient;
function GetServiceSoap(UseWSDL: Boolean; Addr: string): ServiceSoap;
const
defWSDL = 'http://10.16.66.16/KiTest/service.asmx?wsdl';
defURL = 'http://10.16.66.16/KiTest/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;
RIO := THTTPRIO.Create(nil);
try
if UseWSDL then
begin
RIO.WSDLLocation := Addr;
RIO.Service := defSvc;
RIO.Port := defPrt;
end else
RIO.URL := Addr;
Result := (RIO as ServiceSoap);
finally
if Result = nil then
RIO.Free;
end;
end;initialization
InvRegistry.RegisterInterface(TypeInfo(ServiceSoap), 'http://tempuri.org/', 'utf-8');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(ServiceSoap), 'http://tempuri.org/%operationName%');
RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfString), 'http://tempuri.org/', 'ArrayOfString');
end.
以下为调用代码
procedure TForm1.Button1Click(Sender: TObject);
var
saa:ServiceSoap;
str:string;
begin
str := 'abc';
saa := GetServiceSoap();
edit1.text := saa.Confirm(str);
end;谢谢!
function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ServiceSoap;
以前用的时候总感觉动态创建HTTPRIO会有问题,所以最好能在窗体上放一个HTTPRIO,调用的时候带过去
function GetServiceSoap(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): ServiceSoap;
var
RIO: THTTPRIO;
defWSDL, defURL, defSvc, defPrt: string;
begin
CoInitialize(nil);
if HTTPRIO <> nil then
begin
With HTTPRIO do
begin
defWSDL = 'http://10.16.66.16/KiTest/service.asmx?wsdl';
defURL = 'http://10.16.66.16/KiTest/service.asmx';
defSvc = 'Service';
defPrt = 'ServiceSoap';
end;
end; 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 IWebServiceAPI);
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;
CoUnInitialize;
end;