IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

XMLRAD Discussion :

WebService et dataset


Sujet :

XMLRAD

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 98
    Points : 57
    Points
    57
    Par défaut WebService et dataset
    Bonjour,

    J'essaie de mettre en place un webservice qui doit renvoyer un flux à une application externe. Ce flux est constitué par un DBExtract renvoyant un certain nombre de lignes.

    Comment inscrire dans le WSDL que le flux retourné est un dataset et pas un seul enregistrement ?

    J'aurai d'autres questions par la suite, mais si quelqu'un a déjà mis en place une solution, ça m'intéresse

    Merci d'avance

  2. #2
    Membre actif Avatar de Jeweller
    Inscrit en
    Août 2003
    Messages
    357
    Détails du profil
    Informations forums :
    Inscription : Août 2003
    Messages : 357
    Points : 278
    Points
    278
    Par défaut
    Il faut associer un fichier XSD et décrire le dataset retourné dans ton xsd... ensuite le client invoque ton wsdl avec documentstyle=rpc.

    Voici un exemple de XSD:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" elementFormDefault="qualified" id="DATASET">
    	<xsd:element name="DATASET" msdata:IsDataSet="true" msdata:Locale="fr-FR">
    		<xsd:complexType>
    			<xsd:choice minOccurs="0" maxOccurs="unbounded">
    				<xsd:element name="VAR">
    					<xsd:complexType>
    						<xsd:sequence>
    							<xsd:element name="ID_CODLAN" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="ID_NOM" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="ST_VAL" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="ST_ABR" type="xsd:string" minOccurs="0"/>
    						</xsd:sequence>
    					</xsd:complexType>
    				</xsd:element>
    			</xsd:choice>
    		</xsd:complexType>
    	</xsd:element>
    	<xsd:element name="EOF" type="xsd:int"/>
    	<xsd:element name="RowCount" type="xsd:int"/>
    	<xsd:element name="LastRow" type="xsd:int"/>
    	<xsd:element name="StartingRow" type="xsd:int"/>
    	<xsd:element name="MESSAGE" type="xsd:string"/>
    	<xsd:element name="MESSAGETYPE" type="xsd:int"/>
    	<xsd:element name="VALIDITY" type="xsd:int"/>
    </xsd:schema>
    Il faut bien sur s'arranger pour que le XSD soit exactement la sortie de ton xmlrgam.

    Michael

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 98
    Points : 57
    Points
    57
    Par défaut
    Merci pour la réponse.

    Quand c'est une autre application xmlRad qui invoque le WebService, en utilisant le wizard, tout se passe bien, sans fichier XSD

    Mais quand tu écris "Il faut associer un fichier XSD et décrire le dataset retourné dans ton xsd... ", comment faut-il comprendre "associer le fichier XSD" ?
    Je l'ai créé comme tu me l'as indiqué et je l'ai mis dans le même dossier que le service, mais comment l'associer au fichier WSDL (ou, pour le dire autrement, comment l'intégrer dans le fichier WSDL que je n'ai pas réussi à localiser : il est construit dynamiquement à chaque appel ?) ?

    Merci d'avance pour ta réponse.

  4. #4
    Membre actif Avatar de Jeweller
    Inscrit en
    Août 2003
    Messages
    357
    Détails du profil
    Informations forums :
    Inscription : Août 2003
    Messages : 357
    Points : 278
    Points
    278
    Par défaut
    Salut,
    Chaque XMLService à une propriété XSD (en plus des XSL, XMLGRAM, ...) qu'il convient de renseigner avec ton fichier XSD.
    Le WSDL est effectivement généré dynamiquement à chaque appel en listant les XMLServices "published". Si tu changes le Bindingstyle par défaut à "document" le WSDL tient (normalement, il y avait qqs bugs à ce sujet fut un temps) compte des XSD:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    http://localhost/MaDLLBin/Ma.dll/WSDL?BindingStyle=document
    En ce qui me concernce c'est une fonction essentielle qui nous permet de consommer les Ws depuis VS.Net.

    Michael

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 98
    Points : 57
    Points
    57
    Par défaut
    Bien. Ça progresse, mais je n'arrive pas à inclure le fichier xsd dans le wsdl. J'ai bien rattaché le fichier xsd au service comme tu me l'as indiqué.

    Voilà un extrait de la grappe XML générée :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <document>
    <EspadonInscrits EOF="1" StartingRow="0" LastRow="3541" RowCount="3542" ExactPaging="0" CurrentPage="1" MaxRows="-1" RecordName="INSCRIT">
    <INSCRIT>
    <ID_NATIONAL>1701038531A</ID_NATIONAL>
    <NOM_ELEVE>ARROUET</NOM_ELEVE>
    <PRENOM_ELEVE>Sullivan</PRENOM_ELEVE>
    <DATE_NAISS_ELE>13/09/1990</DATE_NAISS_ELE>
    <SEXE_ELEVE>1</SEXE_ELEVE>
    <STATUT>I</STATUT>
    <CODE_RNE>0440033X</CODE_RNE>
    <CODE_MEF>31123410220</CODE_MEF>
    </INSCRIT>
    ... plein d'<INSCRIT>
    </document>
    Voilà le fichier xsd :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" elementFormDefault="qualified" id="EspadonInscrits">
    	<xsd:element name="EspadonInscrits" msdata:IsDataSet="true" msdata:Locale="fr-FR">
    		<xsd:complexType>
    			<xsd:choice minOccurs="0" maxOccurs="unbounded">
    				<xsd:element name="INSCRIT">
    					<xsd:complexType>
    						<xsd:sequence>
    							<xsd:element name="ID_NATIONAL" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="NOM_ELEVE" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="PRENOM_ELEVE" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="DATE_NAISS_ELE" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="SEXE_ELEVE" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="STATUT" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="CODE_RNE" type="xsd:string" minOccurs="0"/>
    							<xsd:element name="CODE_MEF" type="xsd:string" minOccurs="0"/>
    						</xsd:sequence>
    					</xsd:complexType>
    				</xsd:element>
    			</xsd:choice>
    		</xsd:complexType>
    	</xsd:element>
    	<xsd:element name="EOF" type="xsd:int"/>
    	<xsd:element name="StartingRow" type="xsd:int"/>
    	<xsd:element name="LastRow" type="xsd:int"/>
    	<xsd:element name="RowCount" type="xsd:int"/>
    	<xsd:element name="ExactPaging" type="xsd:int"/>
    	<xsd:element name="CurrentPage" type="xsd:int"/>
    	<xsd:element name="MaxRows" type="xsd:int"/>
    	<xsd:element name="RecordName" type="xsd:string"/>
    </xsd:schema>
    et voilà ce que donne le WSDL :
    http://minilien.fr/a0lc9x

    Il y a forcément quelque chose que je n'ai pas bien fait, mais quoi ??

    Merci encore.

  6. #6
    Membre actif Avatar de Jeweller
    Inscrit en
    Août 2003
    Messages
    357
    Détails du profil
    Informations forums :
    Inscription : Août 2003
    Messages : 357
    Points : 278
    Points
    278
    Par défaut
    Si tu es en XMLRAD2007, je crois malheureusement que le xmlservice "WSDL" est buggé, le bindingstyle document ne fonctionne pas/plus. Il me semble que j'ai du reprendre celui de XMLRAD2006 (voir XMLAdm_dmd.pas - WSDLBeforeXMLService ). De plus les namespaces variables, qui dépendent du nom de l'instance, etc... bref c'est pas génial, on a du pas mal faire le ménage pour que ce soit fonctionnel et généralisable.
    Mais au bout du compte ca fonctionne bien, même si on se bat un peu avec les encoding...

    Pour ton cas, remplace la procédure BuildMessage par celle de XMLRAD2006, recompile et ca devrait faire l'affaire.

    Michael

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 98
    Points : 57
    Points
    57
    Par défaut
    J'avais oublié de préciser que j'étais déjà en XMLRAD 2006 R1...

    Pour essayer d'être le plus cohérent possible, j'ai utilisé la fonction d'Xmlrad : générer le fichier xsd, qui m'a donné ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?xml version="1.0" encoding="ISO-8859-15"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    	<xsd:attribute name="EOF" type="xsd:string"/>
    	<xsd:attribute name="StartingRow" type="xsd:string"/>
    	<xsd:attribute name="LastRow" type="xsd:string"/>
    	<xsd:attribute name="RowCount" type="xsd:string"/>
    	<xsd:attribute name="ExactPaging" type="xsd:string"/>
    	<xsd:attribute name="CurrentPage" type="xsd:string"/>
    	<xsd:attribute name="MaxRows" type="xsd:string"/>
    	<xsd:attribute name="RecordName" type="xsd:string"/>
    	<xsd:element name="document">
    		<xsd:complexType>
    			<xsd:all>
    				<xsd:element ref="EspadonInscrits" minOccurs="0"/>
    			</xsd:all>
    		</xsd:complexType>
    	</xsd:element>
    	<xsd:element name="EspadonInscrits">
    		<xsd:complexType>
    			<xsd:sequence>
    				<xsd:element ref="INSCRIT" minOccurs="0" maxOccurs="unbounded"/>
    			</xsd:sequence>
    			<xsd:attribute ref="EOF"/>
    			<xsd:attribute ref="StartingRow"/>
    			<xsd:attribute ref="LastRow"/>
    			<xsd:attribute ref="RowCount"/>
    			<xsd:attribute ref="ExactPaging"/>
    			<xsd:attribute ref="CurrentPage"/>
    			<xsd:attribute ref="MaxRows"/>
    			<xsd:attribute ref="RecordName"/>
    		</xsd:complexType>
    	</xsd:element>
    	<xsd:element name="INSCRIT">
    		<xsd:complexType>
    			<xsd:all>
    				<xsd:element ref="ID_NATIONAL" minOccurs="0"/>
    				<xsd:element ref="NOM_ELEVE" minOccurs="0"/>
    				<xsd:element ref="PRENOM_ELEVE" minOccurs="0"/>
    				<xsd:element ref="DATE_NAISS_ELE" minOccurs="0"/>
    				<xsd:element ref="SEXE_ELEVE" minOccurs="0"/>
    				<xsd:element ref="STATUT" minOccurs="0"/>
    				<xsd:element ref="CODE_RNE" minOccurs="0"/>
    				<xsd:element ref="CODE_MEF" minOccurs="0"/>
    			</xsd:all>
    		</xsd:complexType>
    	</xsd:element>
    	<xsd:element name="ID_NATIONAL" type="xsd:string"/>
    	<xsd:element name="NOM_ELEVE" type="xsd:string"/>
    	<xsd:element name="PRENOM_ELEVE" type="xsd:string"/>
    	<xsd:element name="DATE_NAISS_ELE" type="xsd:string"/>
    	<xsd:element name="SEXE_ELEVE" type="xsd:string"/>
    	<xsd:element name="STATUT" type="xsd:string"/>
    	<xsd:element name="CODE_RNE" type="xsd:string"/>
    	<xsd:element name="CODE_MEF" type="xsd:string"/>
    </xsd:schema>
    Ça n'a malheureusement pas changé grand chose dans le WSDL. Au moins, je me dis que le fichier XSD est propre. (Non ? )

    Je vais essayer de retrouver le thread ou tu parles de tes problèmes avec VS.net liés au webservice et je reviens...

  8. #8
    Membre actif Avatar de Jeweller
    Inscrit en
    Août 2003
    Messages
    357
    Détails du profil
    Informations forums :
    Inscription : Août 2003
    Messages : 357
    Points : 278
    Points
    278
    Par défaut
    Peu importe le XSD tant que le schéma décris correspond au format des données retournées. L'idée c'est que ce XSD soit copié dans le WSDL au niveau de la description de la sortie du WebService. C'est le binding style à document (à l'inverse du mode rpc) qui fait cela. Tu positionnes bien ce paramètre ?

    Michael

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 98
    Points : 57
    Points
    57
    Par défaut
    Oui, tu peux le vérifier avec le minilien dans une de mes précédentes réponses.

    Le fichier XSD est bien référencé dans le service, tout me semble correct , mais impossible de voir le XSD dans le WSDL. J'ai pourtant l'impression d'être tout près de la solution.

    Je vais tracer le XMLAdm_dmd.pas pour essayer de comprendre. J'y ai déjà vu que, effectivement, BindingStyle=document était plus qu'important !

    Si tu as une (autre) idée de génie :-)

  10. #10
    Membre actif Avatar de Jeweller
    Inscrit en
    Août 2003
    Messages
    357
    Détails du profil
    Informations forums :
    Inscription : Août 2003
    Messages : 357
    Points : 278
    Points
    278
    Par défaut
    Effectivement.
    J'ai regardé dans mes anciennes sources en XMLRAD2006... le fameux beug y etait déjà. Il faut revenir à la version de XMLRAD2005. Voici celle qui fonctionnait pour moi pour XMLRAD2006:

    Notez qu'il y a d'autres modif faite "en dur" pour le support de VS qu'il faudra peut etre retroucher. (voir dans le corps principal)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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;
    Michael

  11. #11
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 98
    Points : 57
    Points
    57
    Par défaut
    Merci pour l'info. Je m'étais effectivement rendu compte que la procédure qui intégrait le schéma n'était jamais appelée.

    J'ai mis en place tes modifications, mais maintenant j'ai une erreur : Cannot found XMLService...

  12. #12
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 98
    Points : 57
    Points
    57
    Par défaut
    ...et j'ai créé une application avec XMLRAD 2005, et le schéma n'est toujours pas intégré.

    Il y a juste :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    <xsd:schema targetNamespace="http://azereg:8080/EspadonBin/wsdl"><xsd:element name="Inscrits"><xsd:complexType>
    <xsd:sequence/>
    </xsd:complexType>
    </xsd:element><xsd:element name="InscritsResponse"><xsd:complexType>
    <xsd:sequence/>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>

  13. #13
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 98
    Points : 57
    Points
    57
    Par défaut
    En traçant le source de XmlAdm_dmd.pas (Xmlrad 2006) , j'ai fait quelques essais et je me suis rendu compte que :

    hôte/WSDL?BindingStyle=document
    ne donnait rien,

    que :

    hôte/WSDL?BindingStyle=document&XMLService=monwebservice

    ne donnait rien, mais que :

    hôte/WSDL?XMLService=monwebservice

    intégrait (enfin !) le schéma XSD dans le WSDL.

    Que faut-il en penser ?

  14. #14
    Membre actif Avatar de Jeweller
    Inscrit en
    Août 2003
    Messages
    357
    Détails du profil
    Informations forums :
    Inscription : Août 2003
    Messages : 357
    Points : 278
    Points
    278
    Par défaut
    "Cannot found XMLServive..." ? Curieux. Et pour le reste ca ressemble au soucis que j'avais mais que j'ai résolu avec la méthode plus haut...

    Voici à tout hasard, la version 2005 de la méthode...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    procedure TdmdXMLAdm.WSDLBeforeXMLService(XMLService: IXMLService; var Handled: Boolean);
    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
    	InstanceName := XMLApplication.InitParams.Values['XMLC_InstanceName'];
      URL := 'http://'+Context.Values['XMLC_Host']+Context.Values['XMLC_ScriptName'];
      TargetNameSpace := URL+'/wsdl';
    //  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;

  15. #15
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    98
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 98
    Points : 57
    Points
    57
    Par défaut
    J'ai repris les modifs que tu avais envoyées hier matin et ça fonctionne (j'avais dû zapper quelque chose hier).

    J'ai corrigé les lignes spécifiques pour VS et le wsdl avec BindingStyle=document génère bien le fichier XSD.

    J'ai oublié de préciser que mon appli est une appli J2EE/Tomcat.

    ... maintenant, je vais envoyer le wsdl au prestataire qui doit se connecter sur l'appli en java, et là j'ai quelques craintes. Les tests qu'il a effectués avec le wsdl d'hier soir ne lui donnent pas accès au webservice. Peut-être avec celui de ce matin ?

    Bref, je risque de revenir...

Discussions similaires

  1. [Web Service] WebService .NET (Dataset)
    Par mike49 dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 17/06/2010, 20h45
  2. dataset, gridview et webservice
    Par Nicopilami dans le forum ASP.NET
    Réponses: 8
    Dernier message: 18/09/2009, 17h58
  3. Question sur les WebService renvoyant un DataSet ?
    Par tazmania dans le forum Services Web
    Réponses: 16
    Dernier message: 07/06/2008, 21h29
  4. WebService, PDA, Oracle et dataset
    Par cheche49 dans le forum Services Web
    Réponses: 4
    Dernier message: 05/03/2008, 18h32
  5. [2.0][C#] WebService et DataSet
    Par Pilloutou dans le forum Windows Mobile
    Réponses: 1
    Dernier message: 23/02/2007, 17h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo