Désolé pour le titre, je n'étais pas très inspiré.
voici mon problème :
je veux créer un webservice en PHP5 qui sera appelé par un client C#/.Net 2.0
Ce web service devra retourner des types complexes. En fait des objets, pas des tableau de chaine.
voici ce que j'ai essayé :
création d'une classe PHP :
ainsi qu'une méthode en dehors de la classe qui retourne un objet AwkScriptDescriptor
Code PHP : 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 class AwkScriptDescriptor { /** * Script Title * * @var string */ public $title = ""; /** * Script unique Id * * @var string */ public $guid = ""; /** * Script program * * @var string */ public $script =""; /** * Script comment * * @var string */ public $comment=""; /** * author * * @var int */ public $idAuthor=0; public function __construct($name) { $this->script = $name; } }
le fichier wsdl de description du service : (pour la pièce jointe, j'ai du renommer le fichier pour qu'il ait l'extension .xml)
Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 /** * Get AwkScript * @param int $id * @return Author */ function getAwkScript($id) { $Script = new AwkScriptDescriptor("toto"); $Script->title="Titre"; $Script->comment="commentaire"; $Script->idAuthor = 7; return $Script; }
Enfin voici le service proprement dit appelé par mon client C# :
Code XML : 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 <?xml version='1.0' encoding='UTF-8'?> <!-- WSDL file generated by PHP WSDLCreator (http://www.protung.ro) --> <definitions name="NppAwkPluginWS" targetNamespace="urn:NppAwkPluginWS" xmlns:typens="urn:NppAwkPluginWS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:NppAwkPluginWS"> <xsd:complexType name="AwkScriptDescriptor"> <xsd:all> <xsd:element name="comment" type="xsd:string"> </xsd:element> <xsd:element name="guid" type="xsd:string"> </xsd:element> <xsd:element name="idAuthor" type="xsd:integer"> </xsd:element> <xsd:element name="script" type="xsd:string"> </xsd:element> <xsd:element name="title" type="xsd:string"> </xsd:element> </xsd:all> </xsd:complexType> </xsd:schema> </types> <message name="getAwkScriptRequest"> <part name="id" type="xsd:integer"> </part> </message> <message name="getAwkScriptResponse"> <part name="getAwkScriptReturn" type="typens:AwkScriptDescriptor"> </part> </message> <message name="getHelloRequest"> <part name="prenom" type="xsd:string"> </part> <part name="nom" type="xsd:string"> </part> </message> <message name="getHelloResponse"> <part name="getHelloReturn" type="xsd:string"> </part> </message> <portType name="AwkScriptDescriptorPortType"> <operation name="getAwkScript"> <documentation> Get AwkScript</documentation> <input message="typens:getAwkScriptRequest"> </input> <output message="typens:getAwkScriptResponse"> </output> </operation> <operation name="getHello"> <documentation> test function</documentation> <input message="typens:getHelloRequest"> </input> <output message="typens:getHelloResponse"> </output> </operation> </portType> <binding name="AwkScriptDescriptorBinding" type="typens:AwkScriptDescriptorPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"> </soap:binding> <operation name="getAwkScript"> <soap:operation soapAction="urn:AwkScriptDescriptorAction"> </soap:operation> <input name="getAwkScriptRequest"> <soap:body namespace="urn:NppAwkPluginWS" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> </soap:body> </input> <output name="getAwkScriptResponse"> <soap:body namespace="urn:NppAwkPluginWS" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> </soap:body> </output> </operation> <operation name="getHello"> <soap:operation soapAction="urn:AwkScriptDescriptorAction"> </soap:operation> <input name="getHelloRequest"> <soap:body namespace="urn:NppAwkPluginWS" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> </soap:body> </input> <output name="getHelloResponse"> <soap:body namespace="urn:NppAwkPluginWS" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> </soap:body> </output> </operation> </binding> <service name="NppAwkPluginWSService"> <port name="AwkScriptDescriptorPort" binding="typens:AwkScriptDescriptorBinding"> <soap:address location="http://127.0.0.1/php2wsdl/example/server.php"> </soap:address> </port> </service> </definitions>
J'essaye d'appeler la méthode décrite plus haut et le service plante avec le message suivant : "SOAP-ERROR: Encoding: Violation of encoding rules"
Code PHP : 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 require_once("AwkScriptDescriptor.php"); // première étape : désactiver le cache lors de la phase de test ini_set("soap.wsdl_cache_enabled", "0"); // on indique au serveur à quel fichier de description il est lié $classmap = array('AwkScriptDescriptor' => 'AwkScriptDescriptor'); $serveurSOAP = new SoapServer('example.wsdl',array('classmap' => $classmap)); // ajouter la fonction getHello au serveur $serveurSOAP->addFunction('getHello'); $serveurSOAP->addFunction('getAwkScript'); // lancer le serveur if ($_SERVER['REQUEST_METHOD'] == 'POST') { $serveurSOAP->handle(); } else { echo 'désolé, je ne comprends pas les requêtes GET, veuillez seulement utiliser POST'; }
je n'arrive pas à trouver de documentation sur la création de webservices complexes en PHP, je tente donc ici de trouver de l'aide. peut-être mon problème vient du fichier wsdl ? ou bien de l'initialisation de l'objet SoapServer ? Je dois avouer que je suis un peu perdu et à cours de documentation ou d'exemple concret.
Merci d'avance pour vos réponses.
Partager