SitePoint Sponsor

User Tag List

Results 1 to 1 of 1

Threaded View

  1. #1
    SitePoint Member mginsburg's Avatar
    Join Date
    May 2005
    Location
    Pittsburgh, PA
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SOAP with php5 and simplexml

    Hi,
    I'm working on a freeBSD machine running apache2, with php5 installed. I am using the php5 soap extension to communicate with a third party wsdl. I am loading the xml from a file using simplexml_load_file. The xml looks fine when i print it out, but when i use the soapCall function, with trace enabled and print out the getLastRequest(), somehow extra nodes were added in. Here is the xml I sent, and the xml that getLastRequest shows:

    This is the xml i import

    Code:
    <CreateNotification>
      <apiVersion>1.1</apiVersion>
      <authorization>
        <username>***********</username>
        <password>***********</password>
        <organizationId>******</organizationId>
      </authorization>
      <notification>
        <method>2</method>
        <cycleDelaySeconds>120</cycleDelaySeconds>
        <cycles>2</cycles>
        <deviceDelaySeconds>120</deviceDelaySeconds>
        <broadcastDuration>360</broadcastDuration>
        <notificationTitle>Creation Test 2</notificationTitle>
        <message>Testing creation of a notification using xml</message>
        <pinRequired>false</pinRequired>
        <leaveMessage>true</leaveMessage>
        <validateRecipient>true</validateRecipient>
        <responseOptions>
          <responseOption>
            <responseText>Yes</responseText>
            <callBridgeString>4125551212</callBridgeString>
          </responseOption>
          <responseOption>
            <responseText>No</responseText>
          </responseOption>
        </responseOptions>
      </notification>
    </CreateNotification>
    And here is the getLastRequest output

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://notification.soap.webservices.com>
      <SOAP-ENV:Body>
        <ns1:createNotification>
          <apiVersion>1.1</apiVersion>
          <authorization>
            <username>**********</username>
            <password>**********</password>
            <organizationId>*****</organizationId>
          </authorization>
          <notification>
            <method>2</method>
            <cycleDelaySeconds>120</cycleDelaySeconds>
            <cycles>2</cycles>
            <deviceDelaySeconds>120</deviceDelaySeconds>
            <broadcastDuration>360</broadcastDuration>
            <notificationTitle>Creation Test 2</notificationTitle>
            <message>Testing creation of a notification using xml</message>
            <pinRequired>false</pinRequired>
            <leaveMessage>true</leaveMessage>
            <validateRecipient>true</validateRecipient>
            <responseOptions>
              <responseOption>
                <item>
                  <responseText>Yes</responseText>
                  <callBridgeString>4125551212</callBridgeString>
                </item>
                <item>
                  <responseText>No</responseText>
                </item>
              </responseOption>
            </responseOptions>
          </notification>
        </ns1:createNotification>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    Here is the PHP

    Code:
    $send_xml = simplexml_load_file('xml/create_notification.xml');
    var_dump($send_xml->asXML());
    
    $wsdl = 'http://www.anysite.com/CreateNotification?wsdl';
    $soap = new soapclient($wsdl, array('trace'=>1));
    $result = $soap->__soapCall('CreateNotification',array('CreateNotificationRequest'=>$send_xml));
    $request = simplexml_load_string($soap->__getLastRequest());
    var_dump($request->asXML());
    From what I can tell, the extra nodes <item>, is a result of soap or simplexml seeing repetitive nodes, and interpreting them as an array. Is there any way to avoid having those <item> nodes inserted? Thanks.

    Mike Ginsburg
    Last edited by mginsburg; May 4, 2005 at 07:36.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •