0

I am trying to use a SOAP thing, but I do not understand SOAP at all. I use the native PHP class but I always get the sae error: "Fault occurred while processing." with this description: "java.lang.NullPointerException".

The call I make begins with:

$client = new SoapClient('http://api.notificationmessaging.com/NMSOAP/NotificationService?wsdl', array( 'trace' => 1, 'exceptions' => 0 ) );

Then the params look like this (modified with dummy data)

$email = '[email protected]';
$encrypt = 'AAAAAAAAAAAAAAAAAAAAAAAAAAA';
$notification_id = 123456789;
$random = 'BBBBBBBBBBBB';
$senddate = '2013-09-09T00:00:00';
$synchrotype = 'NOTHING';
$uidkey = 'EMAIL';

$content = array();
$content[] = array(
    2 => 'TEST'
);

$dyn = array();
$dyn[] = array(
    'FIRSTNAME' => 'John'
);
$dyn[] = array(
    'LASTNAME' => 'Smith'
);

$params = array(
    'email' => $email,
    'encrypt' => $encrypt,
    'notificationId' => $notification_id,
    'random' => $random,
    'senddate' => $senddate,
    'synchrotype' => $synchrotype,
    'uidkey' => $uidkey,
    'content' => $content,
    'dyn' => $dyn
);

I then execute the request like this :

$res = $client->__soapCall( 'sendObject', array( $email, $encrypt, $notification_id, $random, $senddate, $synchrotype, $uidkey, $content, $dyn ) );

I do not know where to begin. I have tried several ways to execute the request but it never works.

I have used several REST interfaces successfully with PHP, but SOAP makes no sense to me. I have read the basic tutorials and I'm still none the wiser, especially since they are apparently not applicable in my case.

The environment works

You're probably going to ask, so: Yes, SOAP is working on the server, as this request returns a valid response :

$requestParams = array(
    'CityName' => 'Berlin',
    'CountryName' => 'Germany'
);

$client = new SoapClient( 'http://www.webservicex.net/globalweather.asmx?WSDL' );
$response = $client->GetWeather( $requestParams );

print_r( $response );

This gives me something like:

<CurrentWeather>
  <Location>Berlin-Tegel, Germany (EDDT) 52-34N 013-19E 37M</Location>
  <Time>Sep 10, 2013 - 09:20 AM EDT / 2013.09.10 1320 UTC</Time>
  <Wind> from the SW (230 degrees) at 9 MPH (8 KT) (direction variable):0</Wind>
  <Visibility> 4 mile(s):0</Visibility>
  <SkyConditions> mostly cloudy</SkyConditions>
  <Temperature> 59 F (15 C)</Temperature>
  <DewPoint> 55 F (13 C)</DewPoint>
  <RelativeHumidity> 87%</RelativeHumidity>
  <Pressure> 29.85 in. Hg (1011 hPa)</Pressure>
  <Status>Success</Status>
</CurrentWeather>

That's very nice to know but I still can't make my own request work... Please don't let this become a tumbleweed, I've already got that badge! Thanks.

EDIT

Here is the example provided in the manual :

    <soapenv:Body>
        <api:sendObject>
            <arg0>
                <content>
                    <entry>
                        <key>1</key>
                        <value>
                        <![CDATA[
                        <table width="600">
                        <tr>
                        <td>
                        <font size="2" face="Arial">Our powerful algorithms already
                        found a matching profile that matches your criteria:
                        <br>Celina72&nbsp;</font>
                        <img src="http://mypath/to/my/image.gif" width="50"
                        height="50" border="0" />
                        </td>]]></value>
                    </entry>
                </content>
                <dyn>
                    <entry>
                        <key>FIRSTNAME</key>
                        <value>john</value>
                    </entry>
                </dyn>
                <email>[email protected]</email>
                <encrypt>BdX7CqkmjSivyBgIcZoN4sPVLkx7FaXGiwsO</encrypt>
                <notificationId>6464</notificationId>
                <random>985A8B992601985A</random>
                <senddate>2008-12-12T00:00:00</senddate>
                <synchrotype>NOTHING</synchrotype>
                <uidkey>EMAIL</uidkey>
            </arg0>
        </api:sendObject>
    </soapenv:Body>
</soapenv:Envelope>

Here is the garbage that my request produces (from __getLastRequest())

<?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.service.nsapi.emailvision.com/" xmlns:ns2="http://xml.apache.org/xml-soap">
        <SOAP-ENV:Body>
            <ns1:sendObject/>
            <param1>AAAAAAAAAAAAAAAAAAAAAAAAAAA</param1>
            <param2>123456789</param2>
            <param3>BBBBBBBBBBBB</param3>
            <param4>2013-09-09T00:00:00</param4>
            <param5>NOTHING</param5>
            <param6>EMAIL</param6>
            <param7>
                <ns2:Map>
                    <item>
                        <key>2</key>
                        <value>TEST</value>
                    </item>
                </ns2:Map>
            </param7>
            <param8>
                <ns2:Map>
                <item>
                    <key>FIRSTNAME</key>
                    <value>John</value>
                </item>
            </ns2:Map>
            <ns2:Map>
                <item>
                    <key>LASTNAME</key>
                    <value>Smith</value>
                </item>
            </ns2:Map>
        </param8>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Where did the email go?

3
  • JSON is best, but irrelevant, what I can say though is if you have an working request look at the raw request vs your raw request. This will usually indicate where you are going wrong. Commented Sep 10, 2013 at 14:20
  • "the raw request vs your raw request". I know I can get my request with __getLastRequest(), but what is THE raw request. (Thanks for your help) Commented Sep 10, 2013 at 14:24
  • Should have phrased that better, the working raw request vs your raw request, but I think Niko below has the right direction Commented Sep 10, 2013 at 14:32

1 Answer 1

3

Your error message is from the server side. Something is wrong with your parameters.

<xs:element name="content">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="entry">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="key" type="xs:int"/>
                        <xs:element minOccurs="0" name="value" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

So basicly the API is waiting something like this:

...
<content>
    <entry>
        <key>xs:int</key>
        <value>xs:string</key>
    </entry>
</content>
...

Try something like this:

$content[] = array(
    'entry' => array(
        array(
            'key'   => 2,
            'value' => 'TEST',
        ),
    ),
);

Also $dyn is incorrectly built.

--- EDIT after this ---

Ok, your request explains quite lot. Using __soapCall() directly without telling keys causes your request to build like that. This could help you out:

$request = array(
    'arg0' => array(
        'content' => array(
            'entry' => array(
                'key'   => 1,
                'value' => 'TESTING',
            ),
        ),
        'dyn' => array(
            'entry' => array(
                'key'   => 'FIRSTNAME',
                'value' => 'john',
            ),
        ),
        'email'             => '[email protected]',
        'encrypt'           => 'BdX7CqkmjSivyBgIcZoN4sPVLkx7FaXGiwsO',
        'notificationId'    => 6464,
        'random'            => '985A8B992601985A',
        'senddate'          => '2008-12-12T00:00:00',
        'synchrotype'       => 'NOTHING',
        'uidkey'            => 'EMAIL',
    ),
);

$result = $client->__soapCall( 'sendObject', array($request) );

Also noticed that there's that "magical" arg0 wrapping the request. Hopefully this helps you! I would also recommend to explore software called SoapUI. It allows you to generate mock services from WSDL and makes you live a lot easier while debugging.

Sign up to request clarification or add additional context in comments.

2 Comments

I have tried this and it makes things worse in terms of XML: it creates <key>KEY</key> and <value>VALUE</value> pairs...
"your request explains quite lot" -> You are a lot smarter than me ;) And IT WORKED! Thank You so much for sticking with it. I had not seen your edit so I went another way, but now with your solution I can make it work natively! Also I had made some progress with SOAP UI, which I had discovered in the meantime. Very helpful indeed. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.