1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
| procedure TdmdXMLAdm.WSDLBeforeXMLService(XMLService: IXMLService; var Handled: Boolean);
(*MODIF 29-08-08 toute la méthode WSDLBeforeXMLService est écrasée par celle de l'ancienne version d'XMLRAD*)
(*ATTENTION!!! DANS LE CORPS DE LA FONCTION, MODIF DU TARGETNAMESPACE POUR SUPPORT VS - > should be a parameter*)
var
TargetNameSpace: WideString;
URL: WideString;
procedure BuildType(Schema, Params: IXMLCursor; ElementName: WideString);
var
complexType: IXMLCursor;
Element: IXMLCursor;
sequence: IXMLCursor;
begin
Element := Schema.AppendChild('xsd:element', '');
Element.SetAttributeValue('name', ElementName);
complexType := Element.AppendChild('xsd:complexType', '');
sequence := complexType.AppendChild('xsd:sequence', '');
while not Params.EOF do
begin
Element := sequence.AppendChild('xsd:element', '');
Element.SetAttributeValue('name', Params.GetValue('Name'));
Element.SetAttributeValue('type', 'xsd:string');
Params.Next;
end;
end;
procedure AppendSchema(Schema, XMLService: IXMLCursor; const XMLPath: WideString);
var
XMLServiceName: WideString;
FileName: WideString;
XMLSchema: IXMLCursor;
Element: IXMLCursor;
begin
FileName := XMLService.GetValue('XSD');
FileName := ConcatDirs([GetAppPath, XMLPath, FileName], False);
XMLSchema := TXMLCursor.Create;
XMLSchema.Load(FileName);
Element := Schema.AppendChild('xsd:element', '');
XMLServiceName := XMLService.GetValue('Name');
Element.SetAttributeValue('name', XMLServiceName+'Response');
Schema := Element.AppendChild('xsd:complexType', '');
Schema := Schema.AppendChild('xsd:sequence', '');
XMLSchema := XMLSchema.Select('*');
Schema.AppendXMLCursor(XMLSchema);
end;
procedure BuildTypes(var Schema: IXMLCursor; Definitions: IXMLCursor);
procedure InternalBuildTypes(XMLModule: TXMLModule);
var
Scope: WideString;
Types: IXMLCursor;
XMLService: IXMLCursor;
begin
XMLService := XMLModule.XMLServices;
if XMLService = nil then
Exit;
XMLService.First;
while not XMLService.EOF do
begin
Scope := WideUpperCase(XMLService.GetValue('Scope'));
if (Scope <> 'PUBLISHED') then
begin
XMLService.Next;
Continue; // Remove protected and private XMLService
end;
if XMLService.GetValue('XSD') = '' then
begin
XMLService.Next;
Continue;
end;
if Schema = nil then
begin
Types := Definitions.AppendChild('types', '');
Schema := types.AppendChild('xsd:schema', '');
Schema.SetAttributeValue('targetNamespace', TargetNameSpace);
end;
AppendSchema(Schema, XMLService, XMLModule.XMLPath);
XMLService.Next;
end;
end;
var
I: Integer;
XMLCollection: TXMLCollection;
XMLCollectionList: TXMLCollectionList;
XMLModule: TXMLModule;
begin
// if Context.Values['XMLService'] = '' then
// Exit;
XMLCollectionList := XMLApplication.GetPool(Context.Values['XMLC_Pool']); // !!! TDO: Loop on all pools
if XMLCollectionList.Count = 0 then
Exit;
XMLCollection := XMLCollectionList[0];
for I := 0 to XMLCollection.ModuleCount-1 do
begin
if not (XMLCollection.GetModuleNo(I) is TXMLModule) then
Continue;
XMLModule := TXMLModule(XMLCollection.GetModuleNo(I));
InternalBuildTypes(XMLModule);
end;
end;
procedure BuildMessage(definitions, Schema, XMLService: IXMLCursor; BindingStyleDocument: Boolean);
var
message: IXMLCursor;
part: IXMLCursor;
Params: IXMLCursor;
Types: IXMLCursor;
XMLServiceName: WideString;
begin
XMLServiceName := XMLService.GetValue('Name');
message := definitions.AppendChild('message', '');
message.SetAttributeValue('name', XMLServiceName);
Params := XMLService.Select('InputParams/Param');
if BindingStyleDocument then
begin
part := message.AppendChild('part', '');
part.SetAttributeValue('name', 'Request');
part.SetAttributeValue('element', 'tns:'+XMLServiceName);
if Schema = nil then
begin
Types := definitions.AppendChild('types', '');
Schema := Types.AppendChild('xsd:schema', '');
Schema.SetAttributeValue('targetNamespace', TargetNameSpace);
end;
BuildType(Schema, Params, XMLServiceName);
end else begin
while not Params.EOF do
begin
part := message.AppendChild('part', '');
part.SetAttributeValue('name', Params.GetValue('Name'));
part.SetAttributeValue('type', 'xsd:string');
Params.Next;
end;
end;
message := definitions.AppendChild('message', '');
message.SetAttributeValue('name', XMLServiceName+'Response');
Params := XMLService.Select('OutputParams/Param');
if BindingStyleDocument then
begin
part := message.AppendChild('part', '');
part.SetAttributeValue('name', 'Response');
part.SetAttributeValue('element', 'tns:'+XMLServiceName+'Response');
if Schema = nil then // No XSD appended
begin
Types := definitions.AppendChild('types', '');
Schema := Types.AppendChild('xsd:schema', '');
Schema.SetAttributeValue('targetNamespace', TargetNameSpace);
end;
if XMLService.GetValue('XSD') = '' then
BuildType(Schema, Params, XMLServiceName+'Response');
end else begin
if Params.EOF then
begin
if (Context.Values['XMLService'] <> '') and (XMLService.GetValue('XSD') <> '') then
begin
part := message.AppendChild('part', '');
part.SetAttributeValue('name', 'Response');
part.SetAttributeValue('element', 'tns:'+XMLServiceName+'Response');
end;
end else
begin
while not Params.EOF do
begin
part := message.AppendChild('part', '');
part.SetAttributeValue('name', Params.GetValue('Name'));
part.SetAttributeValue('type', 'xsd:string');
Params.Next;
end;
end;
end;
end;
procedure BuildMessages(definitions, Schema: IXMLCursor; BindingStyleDocument: Boolean);
procedure InternalBuildMessages(XMLModule: TXMLModule);
var
Scope: WideString;
XMLService: IXMLCursor;
begin
XMLService := XMLModule.XMLServices;
if XMLService = nil then
Exit;
XMLService.First;
while not XMLService.EOF do
begin
Scope := WideUpperCase(XMLService.GetValue('Scope'));
if (Scope <> 'PUBLISHED') then
begin
XMLService.Next;
Continue; // Remove protected and private XMLService
end;
BuildMessage(definitions, Schema, XMLService, BindingStyleDocument);
XMLService.Next;
end;
end;
var
I: Integer;
XMLCollection: TXMLCollection;
XMLCollectionList: TXMLCollectionList;
XMLModule: TXMLModule;
XMLComponent: TXMLComponent;
XMLService: IXMLCursor;
begin
XMLCollectionList := XMLApplication.GetPool(Context.Values['XMLC_Pool']); // !!! TDO: Loop on all pools
if XMLCollectionList.Count = 0 then
Exit;
XMLCollection := XMLCollectionList[0];
if Context.Values['XMLService'] <> '' then
begin
XMLComponent := TXMLComponent(XMLCollection.GetComponent(Context.Values['XMLService']));
if XMLComponent = nil then
raise Exception.Create('Cannot found XMLService '+Context.Values['XMLService']);
XMLModule := TXMLModule(XMLComponent.Owner);
if XMLModule = nil then
raise Exception.Create('XMLModule is nil for '+Context.Values['XMLService']);
XMLService := XMLModule.XMLServices;
if XMLService = nil then
Exit;
XMLService.First;
while not XMLService.EOF do
begin
if CompareText(XMLService.GetValue('Name'), Context.Values['XMLService']) = 0 then
begin
BuildMessage(definitions, Schema, XMLService, BindingStyleDocument);
Break;
end;
XMLService.Next;
end;
end else if Context.Values['XMLModule'] <> '' then
begin
XMLModule := TXMLModule(XMLCollection.GetModule(Context.Values['XMLModule']));
if XMLModule = nil then
raise Exception.Create('Cannot found XMLModule '+Context.Values['XMLModule']);
InternalBuildMessages(XMLModule);
end else
begin
for I := 0 to XMLCollection.ModuleCount-1 do
begin
if not (XMLCollection.GetModuleNo(I) is TXMLModule) then
Continue;
XMLModule := TXMLModule(XMLCollection.GetModuleNo(I));
InternalBuildMessages(XMLModule);
end;
end;
end;
procedure BuildOperation(portType, binding, XMLService: IXMLCursor; BindingStyleDocument: Boolean);
var
operation: IXMLCursor;
input: IXMLCursor;
output: IXMLCursor;
SoapBody: IXMLCursor;
SoapOperation: IXMLCursor;
XMLServiceName: WideString;
begin
XMLServiceName := XMLService.GetValue('Name');
operation := portType.AppendChild('operation', '');
operation.SetAttributeValue('name', XMLServiceName);
// May need to replace tns: with wsdlns:
input := operation.AppendChild('input', '');
input.SetAttributeValue('message', 'tns:'+XMLServiceName);
// input.SetAttributeValue('name', XMLServiceName); // requested by ON 20020605 for .Net compatibility
output := operation.AppendChild('output', '');
output.SetAttributeValue('message', 'tns:'+XMLServiceName+'Response');
// output.SetAttributeValue('name', XMLServiceName+'Response'); // requested by ON 20020605 for .Net compatibility
operation := binding.AppendChild('operation', '');
operation.SetAttributeValue('name', XMLServiceName);
SoapOperation := operation.AppendChild('soap:operation', '');
// SoapOperation.SetAttributeValue('soapAction', URL+'/'+XMLServiceName);
SoapOperation.SetAttributeValue('soapAction', XMLServiceName);
input := operation.AppendChild('input', '');
SoapBody := input.AppendChild('soap:body', '');
if BindingStyleDocument then
SoapBody.SetAttributeValue('use', 'literal') // document, required by XDoc, InfoPath
else
SoapBody.SetAttributeValue('use', 'encoded'); // RPC
SoapBody.SetAttributeValue('namespace', TargetNameSpace); // Should be a URL to messages namespace
SoapBody.SetAttributeValue('encodingStyle', 'http://schemas.xmlsoap.org/soap/encoding/');
output := operation.AppendChild('output', '');
SoapBody := output.AppendChild('soap:body', '');
if BindingStyleDocument then
SoapBody.SetAttributeValue('use', 'literal') // document, required by XDoc, InfoPath
else
SoapBody.SetAttributeValue('use', 'encoded'); // RPC
SoapBody.SetAttributeValue('namespace', TargetNameSpace); // Should be a URL to messages namespace
SoapBody.SetAttributeValue('encodingStyle', 'http://schemas.xmlsoap.org/soap/encoding/');
end;
procedure BuildOperations(portType, binding: IXMLCursor; BindingStyleDocument: Boolean);
procedure InternalBuildOperations(XMLModule: TXMLModule);
var
Scope: WideString;
XMLService: IXMLCursor;
begin
XMLService := XMLModule.XMLServices;
if XMLService = nil then
Exit;
XMLService.First;
while not XMLService.EOF do
begin
Scope := WideUpperCase(XMLService.GetValue('Scope'));
if (Scope <> 'PUBLISHED') then
begin
XMLService.Next;
Continue; // Remove protected and private XMLService
end;
BuildOperation(portType, binding, XMLService, BindingStyleDocument);
XMLService.Next;
end;
end;
var
I: Integer;
XMLCollection: TXMLCollection;
XMLCollectionList: TXMLCollectionList;
XMLComponent: TXMLComponent;
XMLModule: TXMLModule;
XMLService: IXMLCursor;
begin
XMLCollectionList := XMLApplication.GetPool(Context.Values['XMLC_Pool']); // !!! TDO: Loop on all pools
if XMLCollectionList.Count = 0 then
Exit;
XMLCollection := XMLCollectionList[0];
if Context.Values['XMLService'] <> '' then
begin
XMLComponent := TXMLComponent(XMLCollection.GetComponent(Context.Values['XMLService']));
if XMLComponent = nil then
raise Exception.Create('Cannot found XMLService '+Context.Values['XMLService']);
XMLModule := TXMLModule(XMLComponent.Owner);
if XMLModule = nil then
raise Exception.Create('XMLModule is nil for '+Context.Values['XMLService']);
XMLService := XMLModule.XMLServices;
if XMLService = nil then
Exit;
XMLService.First;
while not XMLService.EOF do
begin
if CompareText(XMLService.GetValue('Name'), Context.Values['XMLService']) = 0 then
begin
BuildOperation(portType, binding, XMLService, BindingStyleDocument);
Break;
end;
XMLService.Next;
end;
end else if Context.Values['XMLModule'] <> '' then
begin
XMLModule := TXMLModule(XMLCollection.GetModule(Context.Values['XMLModule']));
if XMLModule = nil then
raise Exception.Create('Cannot found XMLModule '+Context.Values['XMLModule']);
InternalBuildOperations(XMLModule);
end else
begin
for I := 0 to XMLCollection.ModuleCount-1 do
begin
if not (XMLCollection.GetModuleNo(I) is TXMLModule) then
Continue;
XMLModule := TXMLModule(XMLCollection.GetModuleNo(I));
InternalBuildOperations(XMLModule);
end;
end;
end;
const
SWSDLDoc = '<definitions name="%s" targetNamespace="%s" xmlns:tns="%s" '
+'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
+'xmlns="http://schemas.xmlsoap.org/wsdl/">';
var
binding: IXMLCursor;
BindingStyleDocument: Boolean;
Content: WideString;
definitions: IXMLCursor;
InstanceName: WideString;
port: IXMLCursor;
portType: IXMLCursor;
// S: WideString;
Schema: IXMLCursor;
service: IXMLCursor;
SoapAddress: IXMLCursor;
SoapBinding: IXMLCursor;
types: IXMLCursor;
begin
(* MODIF 17/02/09 *)
//InstanceName := XMLApplication.InitParams.Values['XMLC_InstanceName'];
InstanceName := 'MaDll';
URL := 'http://'+Context.Values['XMLC_Host']+Context.Values['XMLC_ScriptName'];
// TargetNameSpace := URL+'/wsdl';
TargetNameSpace := 'http://www.mycompany.com/monappli';
(* FIN MODIF *)
// S := Format(SWSDLDoc, [InstanceName, TargetNameSpace, ) // Should be WideFormat but not available on D3, D4, BCB3, ...
definitions := TXMLCursor.Create;
definitions.AppendChild('definitions', '');
definitions.SetAttributeValue('name', InstanceName);
definitions.SetAttributeValue('targetNamespace', TargetNameSpace);
definitions.SetAttributeValue('xmlns:tns', TargetNameSpace);
definitions.SetAttributeValue('xmlns:soap', 'http://schemas.xmlsoap.org/wsdl/soap/');
definitions.SetAttributeValue('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
{$IFDEF MSWINDOWS}
// definitions.SetAttributeValue('xmlns', 'http://schemas.xmlsoap.org/wsdl/');
{$ENDIF}
BindingStyleDocument := False;
if Context.Values['BindingStyle'] = 'document' then
BindingStyleDocument := True;
Schema := nil;
if BindingStyleDocument then
begin
BuildTypes(Schema, definitions);
end else
begin
types := definitions.AppendChild('types', '');
Schema := types.AppendChild('xsd:schema', '');
Schema.SetAttributeValue('targetNamespace', TargetNameSpace);
end;
BuildMessages(definitions, Schema, BindingStyleDocument);
portType := definitions.AppendChild('portType', '');
portType.SetAttributeValue('name', InstanceName+'PortType');
binding := definitions.AppendChild('binding', '');
binding.SetAttributeValue('name', InstanceName+'Binding');
// May need to replace tns: with wsdlns:
binding.SetAttributeValue('type', 'tns:'+InstanceName+'PortType');
SoapBinding := binding.AppendChild('soap:binding', '');
if BindingStyleDocument then
SoapBinding.SetAttributeValue('style', 'document')
else
SoapBinding.SetAttributeValue('style', 'rpc');
SoapBinding.SetAttributeValue('transport', 'http://schemas.xmlsoap.org/soap/http');
BuildOperations(portType, binding, BindingStyleDocument);
service := definitions.AppendChild('service', '');
service.SetAttributeValue('name', InstanceName+'Service');
service.SetValue('documentation', 'Provides access to all XMLServices defined in '+InstanceName);
port := service.AppendChild('port', '');
port.SetAttributeValue('name', InstanceName+'Port');
port.SetAttributeValue('binding', 'tns:'+InstanceName+'Binding');
SoapAddress := port.AppendChild('soap:address', '');
SoapAddress.SetAttributeValue('location', URL);
XMLRequest.SetContentType('text/xml');
Content := definitions.XML;
Content := TranslateStrToStr(Content, 'xmlns:xsd="http://www.w3.org/2001/XMLSchema"', 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"');
XMLRequest.SetContent(Content);
Handled := True;
end; |
Partager