0

Hi there

I'm new to soap and I'm using the NuSOAP library. I'm trying to send xml to a soap server and then receive a response. I'm getting nowhere with this and it's beginning to frustrate me.

Here is what I was provided with:

First Snippet

POST /Submit.asmx HTTP/1.1
Host: xxxxxxx.co.za
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.xxxxxxx.co.za/SubmitLead"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SubmitLead xmlns="http://www.xxxxxxx.co.za/">
      <xmlLead>xml</xmlLead>
    </SubmitLead>
  </soap:Body>
</soap:Envelope>

Second Snippet

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SubmitLeadResponse xmlns="http://www.xxxxxxx.co.za/">
      <SubmitLeadResult>string</SubmitLeadResult>
    </SubmitLeadResponse>
  </soap:Body>
</soap:Envelope>

As far as I can tell, the first code snippet is for submitting to the soap server and the second snippet is for receiving a response. I've had no luck receiving a response and I'm not even sure if the data I'm sending is actually being received from the server.

Here is my code:

$name = 'test';
$email = 'test@test.com';
$cell = '0123456789';
$stockid = '1234567';
$ref = time();

$xmlLead = '<?xml version="1.0" encoding="UTF-8"?>
<Lead>
    <General>
        <dealer type="IX">419</dealer>
        <source ref="'.$ref.'">string</source>
        <enquiry>1</enquiry>
        <subtype>4</subtype>
        <comment />
    </General>
    <Prospect>
        <title />
        <name>'.$name.'</name>
        <surname />
        <email>'.$email.'</email>
        <home />
        <work />
        <mobile>'.$cell.'</mobile>
        <idnumber />
        <comment />
        <area />
        <national>true</national>
        <license>true</license>
    </Prospect>
    <Item>
        <id>'.$stockid.'</id>
        <purchaseDate />
    </Item>
</Lead>';

require_once('lib/nusoap.php');

$soapclient = new nusoap_client('http://xxxxxxx.co.za/Submit.asmx?WSDL');

$submit_lead = $soapclient->call('SubmitLead',
            $xmlLead,
            NULL,
            'http://www.xxxxxxx.co.za/SubmitLead'
        );

$lead_response = $soapclient->call('SubmitLeadResponse',
            array('SubmitLeadResult'),
            NULL,
            'http://www.xxxxxxx.co.za/SubmitLead'
        );

echo $lead_response;

Please help me figure out what I'm doing wrong?

Edited by Venom Rush

3
Contributors
23
Replies
31
Views
5 Years
Discussion Span
Last Post by diafol
0

Thanks for that pritaeas! The debugging section is going to help me a lot. I'll feed back once I've gone through the documentation and done some testing.

0

Ok. So it looks as if my xml is being read as html. Here's a debug of my request and response. How do I go about fixing this?

Request

POST /Submit.asmx?WSDL HTTP/1.0
Host: xxxxxxx.co.za
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: "http://www.xxxxxxx.co.za/SubmitLead"
Content-Length: 1249

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><SubmitLead><xmlLead xsi:type="xsd:string">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Lead&gt;
    &lt;General&gt;
        &lt;dealer type=&quot;IX&quot;&gt;419&lt;/dealer&gt;
        &lt;source ref=&quot;1334745558&quot;&gt;string&lt;/source&gt;
        &lt;enquiry&gt;1&lt;/enquiry&gt;
        &lt;subtype&gt;4&lt;/subtype&gt;
        &lt;comment /&gt;
    &lt;/General&gt;
    &lt;Prospect&gt;
        &lt;title /&gt;
        &lt;name&gt;test&lt;/name&gt;
        &lt;surname /&gt;
        &lt;email&gt;test@test.com&lt;/email&gt;
        &lt;home /&gt;
        &lt;work /&gt;
        &lt;mobile&gt;0123456789&lt;/mobile&gt;
        &lt;idnumber /&gt;
        &lt;comment /&gt;
        &lt;area /&gt;
        &lt;national&gt;true&lt;/national&gt;
        &lt;license&gt;true&lt;/license&gt;
    &lt;/Prospect&gt;
    &lt;Item&gt;
        &lt;id&gt;1234567&lt;/id&gt;
        &lt;purchaseDate /&gt;
    &lt;/Item&gt;
&lt;/Lead&gt;</xmlLead></SubmitLead></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response

HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Wed, 18 Apr 2012 10:38:50 GMT
Connection: close
Content-Length: 375

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SubmitLeadResponse xmlns="http://www.xxxxxxx.co.za/"><SubmitLeadResult>No XML Document</SubmitLeadResult></SubmitLeadResponse></soap:Body></soap:Envelope>

What's even more confusing is that my request has a xml declaration before the soap elements.

0

So how do I go about making sure that my xml is read/sent as xml? The response returns "No XML Document" and the type on the xmlLead element is:

xsi:type="xsd:string"

Shouldn't that be xml instead of string?

0

In the link I showed you, he uses:

$result = $client->call('hello', array('name' => 'Scott'));

So, in your case it should be something like:

$result = $client->call('SubmitLead', array('name' => $name));

The array keys are determined by the API, and should be found in the XSD. I can only guess what they are.

This example and this example shows how you can determine your parameters.

Edited by pritaeas: addon

0

I've tried wrapping my xml within simplexml_load_string() and the request is displaying my xml as expected but the response is still giving me "No XML Document"

Edited by Venom Rush

0

Hi pritaeas

I have my call set exactly like that.

$submit_lead = $soapclient->call('SubmitLead',
            array('xmlLead' => $xmlLead),
            NULL,
            'http://www.xxxxxxx.co.za/SubmitLead'
        );

The only difference is that I have a SOAP action specified.

Edited by Venom Rush

0

My point was, that you should not send the XML, but all the individual parameters in arrays. Sorry for not making that clear.

Perhaps this link will explain better.

Edited by pritaeas: addon

0

I just spoke to the developers who handle the soap server and they only process requests that come in the form of xml so that idea won't help...but thanks ;).

0

Well of course. You can see that what's sent is the actual XML. In your PHP code you provide arrays, NuSoap does the rest.

0

Hi pritaeas

I tried using your array suggestion but still no luck. The soap server is receiving my request just fine but for whatever reason it just doesn't like anything I put into the xmlLead element.

0

There's no authentication required.

I have spoken to the developers again and it seems that they validate the <SubmitLead xmlns="http://www.xxxxxxx.co.za/"> element to make sure it's named SubmitLead xmlns="http://www.xxxxxxx.co.za/".

Unfortunately I can't seem to get my code to read the same. Initially I hadn't specified the namspace for the SubmitLead element but after doing so NuSOAP started adding extra info to the element. Example below:

<ns7599:SubmitStringLead xmlns:ns7599="http://www.xxxxxxx.co.za/">

I then decided to use PHP's native soap client and it seems to be doing something similar:

<ns1:SubmitStringLead>

But now the namespace is specified within the soap header instead of the element above. Is there any way of telling the soap client to specify the soap method name exactly as I want it?

Edited by Venom Rush

0

Hmz.... not sure. Generating all the XML yourself will do it of course, although it shouldn't be necessary. Perhaps there is a way, doesn't NuSoap have a forum?

Edited by pritaeas: addon

0

Not that I know of. But I've read on some stackoverflow posts that NuSOAP is no longer in development which is why I decided to try PHP's native soap client.

0

I've done some more reading on the net and it seems that microsoft servers are quite strict when it comes to receiving soap requests. I found an extension to the SoapClient that's supposed to fix my issue but $request only contains my custom xml portion of the request and not the entire soap request as I imagined.

class MSSoapClient extends SoapClient {

    function __doRequest($request, $location, $action, $version) {
        $namespace = "http://www.xxxxxxx.co.za/";

        $request = preg_replace('/<ns1:(\w+)/', '<$1 xmlns="'.$namespace.'"', $request, 1);
        $request = preg_replace('/<ns1:(\w+)/', '<$1', $request);
        $request = str_replace(array('/ns1:', 'xmlns:ns1="'.$namespace.'"'), array('/', ''), $request);

        // parent call
        return parent::__doRequest($request, $location, $action, $version);
    }
}

I was expecting $request to contain the following but it seems to be missing <ns1:SubmitLead>:

<ns1:SubmitLead>
<strXml>
<Lead xmlns="">
    <General>
        <dealer>419</dealer>
        <source ref="1234567">string</source>
        <enquiry>1</enquiry>
        <subtype>4</subtype>
        <comment />
    </General>
    <Prospect>
        <title />
        <name>test</name>
        <surname />
        <email>test@test.com</email>
        <home />
        <work />
        <mobile>0123456789</mobile>
        <idnumber />
        <comment />
        <area />
        <national>true</national>
        <license>true</license>
    </Prospect>
    <Item>
        <id>1234567</id>
        <purchaseDate>Now</purchaseDate>
    </Item>
</Lead>
</strXml>
</ns1:SubmitLead>

Edited by Venom Rush

0

I'm abandoning this thread as I'm no longer using the NuSOAP library. If one of the mods could mark it as closed (if possible) and NOT solved I'd appreciate it.

I've started a new thread here.

0

I'm abandoning this thread as I'm no longer using the NuSOAP library. If one of the mods could mark it as closed (if possible) and NOT solved I'd appreciate it.

WRT closing a thread, we only do this as a rule if we some sort of flame war developing or a thread has gone totally off-piste. While a thread may no longer be useful to the OP, it may still be beneficial to other users, who may wish to carry on the discussion.

@VenomRush
Mark the thread solved to prevent contributors wasting their time working on a solution you no longer require.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.