Use Delphi to call WebService through soap Toolkit 3.0
Install Ms soap Toolkit 3.0 first
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; // you can use the IE proxy server. If the browser proxy comment is used, an error will be returned.
Vwsobj. mssoapinit (TRIM (edit1.text); // edit1.text: = 'HTTP: // 10.35.8.179/test/wsautoupgrade. asmx? WSDL '; input parameters
Showmessage (vwsobj. helloworld ());
End;
End.
{Description of mssoapinit in msdn
Mssoapinit
This method initializes the object implementingIsoapclientInterface using the Web Services Description Language (WSDL) file as input. All the operations in the identified service are bound toIsoapclientObject during initialization. Thus, you can call the operations defined in the service usingIsoapclientObject.
HRESULT mssoapinit(
BSTR bstrWSDLFile,
BSTR bstrServiceName,
BSTR bstrPort,
BSTR bstrWSMLFile
);
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,
MssoapinitMethod uses the first service in the specified WSDL file when initializing
IsoapclientImplementation.
-
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,
MssoapinitMethod uses the first port in the specified service when initializing
IsoapclientImplementation.
-
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.
Value |
Description |
S_ OK |
Success. |
E_notimpl |
The function contains no implementation. |
E_outofmemory |
Out of memory. |
Remarks
TheMssoapinitMethod is part of the high-level API on the client side. to use this method, first you simply createSoapclientObject on the client.SoapclientObject implementsIsoapclientInterface. Then, you callMssoapinitMethod 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
}
The following is an excerpt from the Internet, not verified
Appendix:
1. Use JavaScript to call
// Use the specific address
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
// Use the specific user name and password
Username = "0410307444"
Password = "00000"
Res = soapclient. xscheckpassword (username, password)
Wscript. Echo ("Return Value:" + Res)
Ii. asp call written in the VB background
<HTML>
<Head>
<Title> webservie demonstration </title>
</Head>
<Body>
<%
Dim soapclient
'Use the specific address
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
'Use the specific user name and password
Username = "0410307444"
Password = "00000"
Res = soapclient. xscheckpassword (username, password)
Res = soapclient. zfcwjk ("","","","","")
%>
<H1> webservie demonstration <B> returned results: </B> <% = res %> <p>
</Body>
</Html>