Delphi 通过 Soap toolkit 3.0调用webservice

用Delphi 通过 Soap toolkit 3.0调用webservice

先安装MS Soap toolkit 3.0

unit CallWebServiceByComObject;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Comobj, StdCtrls;

type

TForm1 = class(TForm)

Button1: TButton;

Edit1: TEdit;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

var

vWSObj: OleVariant;

begin

vWSObj := CreateOleObject('MSSOAP.SoapClient30');

vWSObj.clientproperty('ServerHTTPRequest') := true; //可以使用IE的代理服务器,如果使用了浏览器代理注释次行会报错

vWSObj.mssoapinit(trim(Edit1.Text));//Edit1.Text:='http://10.35.8.179/test/WSAutoUpgrade.asmx?wsdl'; 传入参数

ShowMessage(vWSObj.HelloWorld());

end;

end.

{关于MsSoapInit 在MSDN的详细解释

mssoapinit

This method initializes the object implementing the ISoapClient interface using the Web Services Description Language (WSDL) file as input. All the operations in the identified service are bound to the ISoapClient object during initialization. Thus, you can call the operations defined in the service using the ISoapClient object.

HRESULT mssoapinit( 
BSTRbstrWSDLFile,
BSTRbstrServiceName,
BSTRbstrPort,
BSTRbstrWSMLFile
);

Parameters

bstrWSDLFile
[in] URL of the WSDL file that describes the services offered by the server.
bstrServiceName
[in] Optional. Default value is "". The service in the WSDL file that contains the operation specified in the SOAP request. If this parameter is missing, is null, or is an empty string, the mssoapinit method uses the first service in the specified WSDL file when initializing the ISoapClient implementation.
bstrPort
[in] Optional. Default value is "". The name of the port in the WSDL file that contains the operation specified in the SOAP request. If this parameter is missing, is null, or is an empty string, the mssoapinit method uses the first port in the specified service when initializing the ISoapClient implementation.
bstrWSMLFile
[in] Optional. Default value is "". The URL of the Web Services Meta Language (WSML) file. This is a required parameter only when using custom type mappers, as described in Handling Complex Types.

Return Values

The following table describes the common return values.

ValueDescription
S_OKSuccess.
E_NOTIMPLThe function contains no implementation.
E_OUTOFMEMORYOut of memory.

Remarks

The mssoapinit method is part of the high-level API on the client side. To use this method, first you simply create an SoapClient object on the client. The SoapClient object implements the ISoapClient interface. Then, you call the mssoapinit method using the WSDL file name, service name, and port name as parameters. Now, the client can call any operations defined in the WSDL file for the requested service or port.

Requirements

OS Versions: Windows CE .NET 4.0 and later.

Header: Mssoap.h.

Link Library: Uuid.lib.

See Also

A Quick Introduction to WSDL | A Quick Introduction to WSML | ISoapClient

}

下面是从网上摘录,未验证

附:

一、用javascript调用

//使用具体的地址

var WSDL_URL = "http://10.20.10.220/zjdxgc/Service.asmx?wsdl"

WScript.echo("Connecting: " + WSDL_URL)

var soapclient= WScript.CreateObject("MSSOAP.SoapClient30")

soapclient.mssoapinit(WSDL_URL, "", "", "")

var res,username,password

//使用具体的用户名和密码

username="0410307444"

password="00000"

res = soapclient.XSCheckPassword(username,password)

WScript.Echo("返回值:" + res )

二、用vb后台写的asp调用

<HTML>

<HEAD>

<TITLE>webservie演示</TITLE>

</HEAD>

<BODY>

<%

Dim soapclient

'使用具体的地址

Const WSDL_URL = "http://10.20.10.220/zjdxgc/Service.asmx?wsdl"

set soapclient = CreateObject("MSSOAP.SoapClient30")

soapclient.ClientProperty("ServerHTTPRequest") = True

Call soapclient.mssoapinit(WSDL_URL, "", "", "")

Dim res,username,password

'使用具体的用户名和密码

username="0410307444"

password="00000"

res = soapclient.XSCheckPassword(username,password)

res = soapclient.zfcwjk("","","","","")

%>

<h1>webservie演示</h1>

<B>返回结果:</B><%=res%> <P><P>

</BODY>

</HTML>