Her er noget D7 WebService der virker på min Apache server localhost
unit main; // Mainformen med en knap, field og listbox
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDelphiWebServiceClientSample = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Button2: TButton;
ListBox1: TListBox;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DelphiWebServiceClientSample: TDelphiWebServiceClientSample;
implementation
uses soapserver;
{$R *.dfm}
procedure TDelphiWebServiceClientSample.Button1Click(Sender: TObject);
begin
//Set the label caption with the result of calling the "echo" service
label1.caption:=GetVCLWebServicePortType.serviceEcho(edit1.text);
end;
procedure TDelphiWebServiceClientSample.Button2Click(Sender: TObject);
var
input: ArrayOfstring;
i: integer;
result: ArrayOfinteger;
begin
setlength(input,16);
for i := 0 to 9 do begin
input[i]:=inttostr(i);
end;
//Fills the listbox with the integers returned from the service
result:=GetVCLWebServicePortType.StringArrayToIntArray(input);
listbox1.clear;
for i := 0 to high(result) do begin
listbox1.items.add(inttostr(result[i])+ '. linie');
end;
end;
end.
------------------den unit der referers til soapserver er her
// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL :
http://localhost:3569/soapserver.php?wsdl// >Import :
http://localhost:3569/soapserver.php?wsdl:0// Encoding : ISO-8859-1
// Version : 1.0
// (17/10/2007 18:53:04 - - $Rev: 7010 $)
// ************************************************************************ //
unit soapserver; // OBS!!!!! ved deployment skal port :3569 fjernes !!!! det er sat ind ved RUN på debugging serveren.
interface
uses 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" // !:integer - "
http://www.w3.org/2001/XMLSchema" ArrayOfstring = array of WideString; { "
http://localhost"[GblCplx] }
ArrayOfinteger = array of Int64; { "
http://localhost"[GblCplx] }
// ************************************************************************ //
// Namespace :
http://localhost/ // soapAction:
http://localhost/soapserver.php/%operationName% // transport :
http://schemas.xmlsoap.org/soap/http // style : rpc
// binding : VCLWebServiceBinding
// service : VCLWebService
// port : VCLWebServicePort
// URL :
http://localhost:3569/soapserver.php // ************************************************************************ //
VCLWebServicePortType = interface(IInvokable)
['{2E51F07C-1564-1B1B-A2D8-45B42189790A}']
function serviceEcho(const input: WideString): WideString; stdcall;
function StringArrayToIntArray(const input: ArrayOfstring): ArrayOfinteger; stdcall;
end;
function GetVCLWebServicePortType(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): VCLWebServicePortType;
implementation
uses SysUtils;
function GetVCLWebServicePortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): VCLWebServicePortType;
const
defWSDL = '
http://localhost:3569/soapserver.php?wsdl'; //defURL = '
http://localhost:3569/soapserver.php'; defURL = '
http://localhost/soapserver.php'; defSvc = 'VCLWebService';
defPrt = 'VCLWebServicePort';
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 VCLWebServicePortType);
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(VCLWebServicePortType), '
http://localhost/', 'ISO-8859-1');
InvRegistry.RegisterDefaultSOAPAction(TypeInfo(VCLWebServicePortType), '
http://localhost/soapserver.php/%operationName%');
RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfstring), '
http://localhost', 'ArrayOfstring');
RemClassRegistry.RegisterXSInfo(TypeInfo(ArrayOfinteger), '
http://localhost', 'ArrayOfinteger');
end.
------------------------------------på serveren kører dette soapserver.php
<?php
/**
* This file is part of the VCL for PHP project
*
* Copyright (c) 2004-2008 qadram software S.L. <support@qadram.com>
*
* Checkout AUTHORS file for more information on the developers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*/
// ini_set("display_errors",1);
// error_reporting(E_ALL);
require_once("vcl/vcl.inc.php");
//Includes
use_unit("comctrls.inc.php");
use_unit("webservices.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");
/*
* Returns the input
*/
function serviceEcho($input)
{
return($input);
}
/*
* Converts the input array, which are strings, to an array of integers
*/
function StringArrayToIntArray($inputarray)
{
$result = array();
reset($inputarray);
while(list($key, $val) = each($inputarray))
{
$result[] = (int)$val;
}
return($result);
}
//Class definition
class DmSoapServer extends DataModule
{
public $MyWebService = null;
function MyWebServiceAddComplexTypes($sender, $params)
{
//Add the complex type array of strings
$this->MyWebService->addComplexType
(
'ArrayOfstring',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'string[]')),
'xsd:string'
);
//Add the complex type array of integers
$this->MyWebService->addComplexType
(
'ArrayOfinteger',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'integer[]')),
'xsd:integer'
);
}
function MyWebServiceRegisterServices($sender, $params)
{
//Register the echo service
$this->MyWebService->register(
"serviceEcho",
array('input' => 'xsd:string'),
array('return' => 'xsd:string'),
'
http://localhost/' );
//Register the conversion service
$this->MyWebService->register(
"StringArrayToIntArray",
array('input' => 'tns:ArrayOfstring'),
array('return' => 'tns:ArrayOfinteger'),
'
http://localhost/' );
}
}
global $application;
global $DmSoapServer;
//Creates the form
$DmSoapServer = new DmSoapServer($application);
//Read from resource file
$DmSoapServer->loadResource(__FILE__);
?>
----------------------------med denne soapserver.xml.php
<?php
<object class="DmSoapServer" name="dmSoapServer" baseclass="datamodule">
<property name="Height">600</property>
<property name="Name">dmSoapServer</property>
<property name="Width">800</property>
<object class="Service" name="MyWebService" >
<property name="Left">244</property>
<property name="Top">95</property>
<property name="Active">1</property>
<property name="Name">MyWebService</property>
<property name="NameSpace">
http://localhost</property> <property name="SchemaTargetNamespace">
http://localhost/xsd</property> <property name="ServiceName">VCLWebService</property>
<property name="OnAddComplexTypes">MyWebServiceAddComplexTypes</property>
<property name="OnRegisterServices">MyWebServiceRegisterServices</property>
</object>
</object>
?>
-------------------------------------
PHP delen er lavet med Delphi for PHP 2.0
Jeg har været glad for Delphi i 15 år men synes at Internet programmering har været en pine. Jeg ved ikke om du kan huske CGIExpert til D4.
Jeh gar en Visual Studio 2008 Pro på årøve og overvejer vedmodigt om ikke jeg skulle fortsætte med den. Det fungerer men er lidt klodset og Hjælp funktionerne er uoverskuelige.
Bare dog at Delphi for PHP kunne komme med list extra. Et canvas at printe på ville være fint.