je viens de créer un WebService dont voici le contenu de mon fichier WSDL :
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
<?xml version="1.0"?>
<!-- partie 1 : Definitions -->
<definitions name="HistoneCrossway" 
	targetNamespace="urn:HistoneCrossway" 
	xmlns:typens="urn:HistoneCrossway" 
	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/">
 
	<!-- partie 2 : Types-->
	<types>
		<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" 
			targetNamespace="urn:HistoneCrossway">
				<xsd:element name="ContentNIP">
					<xsd:complexType>
						<xsd:sequence>
							<xsd:element name="A" minOccurs="1" maxOccurs="1" type="xsd:string" />
							<xsd:element name="B" minOccurs="0" maxOccurs="1" type="xsd:string" />
							<xsd:element name="C" minOccurs="1" maxOccurs="1" type="xsd:string" />
						</xsd:sequence>
					</xsd:complexType>
				</xsd:element>
		</xsd:schema>
	</types> 
 
	<!-- partie 3 : Message -->
	<message name="getNIPContentIN">
		<part name="nip" type="xsd:string"/>
	</message>
	<message name="getNIPContentOUT">
		<part name="return" type="xsd:ContentNIP"/>
	</message>
 
	<!-- partie 4 : Port Type -->
	<portType name="NIPContentPort">
		<!-- partie 5 : Operation -->
		<operation name="getNIPContent">
			<input message="typens:getNIPContentIN"/>
			<output message="typens:getNIPContentOUT"/>
		</operation>
	</portType>
 
	<!-- partie 6 : Binding -->
	<binding name="NIPContentBinding" type="typens:NIPContentPort">
		<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
		<operation name="getNIPContent">
			<soap:operation soapAction="NIPContentAction"/>
			<input name="getNIPContentIN">
				<soap:body use="encoded" 	
						namespace="urn:HistoneCrossway" 	
						encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
			</input>
			<output name="getNIPContentOUT">
				<soap:body  use="encoded" 	
						namespace="urn:HistoneCrossway" 
						encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
			</output>
		</operation>
	</binding>
 
	<!-- partie 7 : Service -->
	<service name="NIPContentService">
		<documentation>RETOURNE A, B, C</documentation>
		<!-- partie 8 : Port -->
		<port name="NIPContentPort" binding="typens:NIPContentBinding">
			<soap:address location="http://localhost/soap.php"/>
		</port>
	</service>
</definitions>
Ainsi que 2 fichiers PHP :
soap.php qui est le serveur SOAP
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
<?php
ini_set("soap.wsdl_cache_enabled", "0");
$serveurSOAP = new SoapServer('HistoneCrossway.wsdl');
$serveurSOAP->addFunction('getNIPContent');
// 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';
}
function getNIPContent($nip)
{
        return array("A"=>$nip."_A", "B"=>$nip."_B");
}
?>
et mon client SOAP, client-soap.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
<?php
ini_set("soap.wsdl_cache_enabled", "0");
$clientSOAP = new SoapClient('HistoneCrossway.wsdl');
print_r($clientSOAP->getNIPContent('Marc'));
?>
Le problème est le suivant, dans la définition des types j'ai spécifié que l'élément "B" n'était pas obligatoire par le biais de
Code : Sélectionner tout - Visualiser dans une fenêtre à part
minOccurs="0" maxOccurs="1"
et les éléments "A" et "C" sont obligatoire pat le biais de
Code : Sélectionner tout - Visualiser dans une fenêtre à part
minOccurs="1" maxOccurs="1"
. Hors dans ma fonction "getNIPContent", au niveau du serveur, cela ne pose aucun problème de que l'élément "C" ne soit pas spécifié. Est ce normal ? Comment je peux vérifier que l'élément complexe "ContentNIP" respecte bien la définition déclaré ?