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

Bibliothèques et frameworks PHP Discussion :

[Web Service] Comment créer un SoapClient en PHP5x qui consomme un WS .NET


Sujet :

Bibliothèques et frameworks PHP

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    46
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 46
    Par défaut [Web Service] Comment créer un SoapClient en PHP5x qui consomme un WS .NET
    Bonjour,

    C'est la première fois que je "deal" avec la techno WebServices.

    Objectif:
    Je dois faire un SoapClient PHP 5x en mode WSDL qui consomme un WebServices .NET
    Le format du WSDL est en mode DOCUMENT/LITERAL;

    1) Voici uniquement l'opération qui m'intéresse dans la partie "binding" du wsdl:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    	<operation name="CreateExternalIncident">
    	  <soap:operation soapAction="Create" style="document" />
    	  <input>
    		<soap:body use="literal" />
    	  </input>
    	  <output>
    		<soap:body use="literal" />
    	  </output>
    	</operation>
    2) La partie "portType" du wsdl:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    	<operation name="CreateExternalIncident">
    	  <documentation />
    	  <input message="ns:CreateExternalIncidentRequest" />
    	  <output message="ns:CreateExternalIncidentResponse" />
    	</operation>
    3) La partie "message" du wsdl:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    	<message name="CreateExternalIncidentRequest">
    		<part name="CreateExternalIncidentRequest" element="ns:CreateExternalIncidentRequest" />
    	</message>
    	<message name="CreateExternalIncidentResponse">
    		<part name="CreateExternalIncidentResponse" element="ns:CreateExternalIncidentResponse" />
    	</message>
    4) La partie "types" du 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
    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
     
          <xs:element name="CreateExternalIncidentRequest">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="model" type="ns:ExternalIncidentModelType" />
              </xs:sequence>
              <xs:attribute name="attachmentInfo" type="xs:boolean" use="optional" />
              <xs:attribute name="attachmentData" type="xs:boolean" use="optional" />
              <xs:attribute default="true" name="ignoreEmptyElements" type="xs:boolean" use="optional" />
            </xs:complexType>
          </xs:element>
          <xs:element name="CreateExternalIncidentResponse">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="model" type="ns:ExternalIncidentModelType" />
                <xs:element minOccurs="0" name="messages" type="cmn:MessagesType" />
              </xs:sequence>
              <xs:attribute name="status" type="cmn:StatusType" use="required" />
              <xs:attribute name="message" type="xs:string" use="required" />
              <xs:attribute name="schemaRevisionDate" type="xs:date" use="required" />
              <xs:attribute name="schemaRevisionLevel" type="xs:int" use="required" />
              <xs:attribute name="returnCode" type="xs:decimal" use="optional" />
              <xs:attribute name="query" type="xs:string" use="optional" />
            </xs:complexType>
          </xs:element>
     
    	  <xs:complexType name="ExternalIncidentModelType">
            <xs:sequence>
              <xs:element name="keys" type="ns:ExternalIncidentKeysType" />
              <xs:element name="instance" type="ns:ExternalIncidentInstanceType" />
              <xs:element minOccurs="0" name="messages" type="cmn:MessagesType" />
            </xs:sequence>
            <xs:attribute name="query" type="xs:string" use="optional" />
          </xs:complexType>
     
          <xs:complexType name="ExternalIncidentKeysType">
            <xs:sequence>
              <xs:element minOccurs="0" name="IncidentID" nillable="true" type="cmn:StringType" />
            </xs:sequence>
            <xs:attribute name="query" type="xs:string" use="optional" />
          </xs:complexType>
     
          <xs:complexType name="ExternalIncidentInstanceType">
            <xs:sequence>
              <xs:element minOccurs="0" name="IncidentID" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="Category" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="OpenTime" nillable="true" type="cmn:DateTimeType" />
              <xs:element minOccurs="0" name="OpenedBy" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="severity" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="UpdatedTime" nillable="true" type="cmn:DateTimeType" />
              <xs:element minOccurs="0" name="PrimaryAssignmentGroup" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="referral.time" nillable="true" type="cmn:DateTimeType" />
              <xs:element minOccurs="0" name="ClosedTime" nillable="true" type="cmn:DateTimeType" />
              <xs:element minOccurs="0" name="ClosedBy" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="RefExterne" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="ClosureCode" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="ConfigurationItem" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="Location" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="IncidentDescription">
                <xs:complexType>
                  <xs:complexContent mixed="false">
                    <xs:extension base="cmn:ArrayType">
                      <xs:sequence>
                        <xs:element minOccurs="0" maxOccurs="unbounded" name="IncidentDescription" type="cmn:StringType" />
                      </xs:sequence>
                    </xs:extension>
                  </xs:complexContent>
                </xs:complexType>
              </xs:element>
              <xs:element minOccurs="0" name="Resolution">
                <xs:complexType>
                  <xs:complexContent mixed="false">
                    <xs:extension base="cmn:ArrayType">
                      <xs:sequence>
                        <xs:element minOccurs="0" maxOccurs="unbounded" name="Resolution" type="cmn:StringType" />
                      </xs:sequence>
                    </xs:extension>
                  </xs:complexContent>
                </xs:complexType>
              </xs:element>
              <xs:element minOccurs="0" name="AssigneeName" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="Contact" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="JournalUpdates">
                <xs:complexType>
                  <xs:complexContent mixed="false">
                    <xs:extension base="cmn:ArrayType">
                      <xs:sequence>
                        <xs:element minOccurs="0" maxOccurs="unbounded" name="JournalUpdates" type="cmn:StringType" />
                      </xs:sequence>
                    </xs:extension>
                  </xs:complexContent>
                </xs:complexType>
              </xs:element>
              <xs:element minOccurs="0" name="ContactLastName" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="ContactFirstName" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="Company" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="BriefDescription" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="TicketOwner" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="UpdatedBy" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="IMTicketStatus" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="Subcategory" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="SLAAgreementID" nillable="true" type="cmn:DecimalType" />
              <xs:element minOccurs="0" name="ProductType" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="ProblemType" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="ResolutionFixType" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="resolved.by" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="site.visit.date" nillable="true" type="cmn:DateTimeType" />
              <xs:element minOccurs="0" name="site.visit.technician" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="resolved.time" nillable="true" type="cmn:DateTimeType" />
              <xs:element minOccurs="0" name="Solution">
                <xs:complexType>
                  <xs:complexContent mixed="false">
                    <xs:extension base="cmn:ArrayType">
                      <xs:sequence>
                        <xs:element minOccurs="0" maxOccurs="unbounded" name="Solution" type="cmn:StringType" />
                      </xs:sequence>
                    </xs:extension>
                  </xs:complexContent>
                </xs:complexType>
              </xs:element>
              <xs:element minOccurs="0" name="InitialImpact" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="EMSCategory" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="EMSPrimaryGroupe" nillable="true" type="cmn:StringType" />
              <xs:element minOccurs="0" name="attachments" nillable="true" type="cmn:AttachmentsType" />
            </xs:sequence>
            <xs:attribute name="query" type="xs:string" use="optional" />
            <xs:attribute name="uniquequery" type="xs:string" use="optional" />
            <xs:attribute name="recordid" type="xs:string" use="optional" />
          </xs:complexType>
    Note:

    Ce wsdl est lié à un fichier .xsd le type qui m'intéresse est StringType, voir la pièce jointe.

    Voici une ébauche de mon code actuellement:
    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
     
    <?php
    error_reporting(E_ALL);
    ini_set('soap.wsdl_cache_enabled', '0'); // TODO remove in production env
     
    class CreateExternalIncidentRequest {
    	public $model;
      	public $attachmentInfo;
      	public $attachmentData;
      	public $ignoreEmptyElements;
    }
     
    class CreateExternalIncidentResponse {
    	public $model;
      	public $messages;
      	public $status;
      	public $message;
      	public $schemaRevisionDate;
      	public $schemaRevisionLevel;
      	public $returnCode;
      	public $query;
    }
     
    class ExternalIncidentModelType {
    	public $keys;
    	public $instance;
    	public $messages;
    	public $query;
    }
     
    class ExternalIncidentKeysType {
    	public $IncidentID;
    	public $query;
    }
     
    class ExternalIncidentInstanceType {
        public $Company = "AFA";
        public $BriefDescription = "brief";
        public $Contact = "David";
        public $EMSCategory = "emscat";
        public $Category = "cat";
        public $Subcategory = "subcat";
        public $ProductType = "prodtype";
        public $ProblemType = "probtype";
        public $EMSPrimaryGroupe = "emspri";
        public $PrimaryAssignmentGroup = "primassign";
        public $InitialImpact = "initial";
        public $severity = "severity 9"; 
    }
     
    $wsdlFile		= "path to my file.wsdl";
    $wsdlLogin		= "the login";
    $wsdlPassword	= "the password";
     
    $classMap 		= array('CreateExternalIncidentRequest'		=> 'CreateExternalIncidentRequest',
    						'CreateExternalIncidentResponse'	=> 'CreateExternalIncidentResponse',
    						'ExternalIncidentModelType'			=> 'ExternalIncidentModelType',
    						'ExternalIncidentKeysType'			=> 'ExternalIncidentKeysType',
    						'ExternalIncidentInstanceType'		=> 'ExternalIncidentInstanceType');
     
    	// TODO remove trace option in production
    	$authParams	= array('login'		=> $wsdlLogin,
    						'password'	=> $wsdlPassword,
    						'exceptions'=> false,
    						'trace'		=> true,
    						'classmap'	=> $classMap);
     
    	$soapClient = new SoapClient($wsdlFile, $authParams);
     
    	//$parameters = HOW TO ?
    	//$response = $soapClient->CreateExternalIncident($parameters);
    	//var_dump($response);
     
    	// Deal with error
    	if (is_soap_fault($response)) {
    		print "<pre>\n";
    		print "Last request :\n".htmlspecialchars($soapClient->__getLastRequest()) ."\n";
    		print "Last Response:\n".htmlspecialchars($soapClient->__getLastResponse())."\n";
    		print "</pre>"; 
    		print "SOAP Fault: (faultcode: {$response->faultcode}, faultstring: {$response->faultstring}, detail: {$response->detail})";
    	}
    ?>
    Je sais qu'un serveur WebServices en .NET marche uniquement avec un objet en paramètre;
    pour le moment je n'arrive pas à implémenter la solution, c'est à dire comment associer les classes et les types (dois-je dans mon cas utiliser l'option classmap?);
    comment passer ma structure au call soap etc ...

    Quelqu'un pourrait m'orienter, suis-je sur la bonne voie?

    Merci d'avance.

    David


    Finalement j'ai trouvé mon problème, les paramètres étaient mal "nested"
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. Réponses: 4
    Dernier message: 18/04/2012, 21h39
  2. [Web Service][PHP] Créer une interface ActiveSync
    Par manuuu dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 18/11/2010, 12h02
  3. Réponses: 2
    Dernier message: 22/02/2008, 16h14
  4. Réponses: 2
    Dernier message: 16/05/2007, 16h13
  5. Web service comment faire?
    Par albanovisch dans le forum Bibliothèques
    Réponses: 4
    Dernier message: 02/02/2007, 11h33

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