1,593
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public int Sub(int a, int b)//两个整数相减
{
return a - b;
}
}
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL : http://10.18.1.27/webService/Service.asmx?WSDL
// Encoding : utf-8
// Version : 1.0
// (2009-05-04 13:23:01 - $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.
// ************************************************************************ //
// !:int - "http://www.w3.org/2001/XMLSchema"
// ************************************************************************ //
// Namespace : http://tempuri.org/
// soapAction: http://tempuri.org/Sub
// transport : http://schemas.xmlsoap.org/soap/http
// binding : ServiceSoap
// service : Service
// port : ServiceSoap
// URL : http://10.18.1.27/webService/Service.asmx
// ************************************************************************ //
ServiceSoap = interface(IInvokable)
['{77573149-9C57-FA51-F11F-EFD527C91BD9}']
function Sub(const a: Integer; const b: Integer): Integer; 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.18.1.27/webService/Service.asmx?WSDL';
defURL = 'http://10.18.1.27/webService/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/Sub');
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls, DB, ADODB,InvokeRegistry, Rio, SOAPHTTPClient ;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Service;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
rtn: Integer;
ws: ServiceSoap;
begin
ws:= GetServiceSoap(false,'');
rtn:= ws.Sub(13,5);//计算13减去5的结果
showmessage('返回结果: '+ intToStr(rtn));
end;
end.
InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);