NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
PHP Soap Client Help


Joined: 16 Dec 2007
Posts: 5
Reply with quote
I am trying to write a client in php to talk to a webservice by sending 4 strings as a complex type and then supposed
to return an array with 2 elements for each brand in the array (code, name).Using latest ver. of php with nusoap lib.

Below is copy of the wsdl.

Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions 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/"
 xmlns:tns="http://www.mycompany.com/soap"
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 xmlns="http://schemas.xmlsoap.org/wsdl/"
 targetNamespace="http://www.mycompany.com/soap">
 <types>
  <xsd:schema targetNamespace="http://www.mycompany.com/soap">
   <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
   <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
   <xsd:complexType name="brandlistReqData">
    <xsd:all>
     <xsd:element name="xmlUser" type="xsd:string"/>
     <xsd:element name="xmlPassword" type="xsd:string"/>

     <xsd:element name="serviceName" type="xsd:string"/>
     <xsd:element name="serviceMode" type="xsd:string"/>
    </xsd:all>
   </xsd:complexType>
   <xsd:complexType name="brands">
    <xsd:all>
     <xsd:element name="code" type="xsd:string"/>
     <xsd:element name="name" type="xsd:string"/>
    </xsd:all>

   </xsd:complexType>
   <xsd:complexType name="BrandsArray">
    <xsd:complexContent>
     <xsd:restriction base="SOAP-ENC:Array">
      <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:Brands[]"/>
     </xsd:restriction>
    </xsd:complexContent>
   </xsd:complexType>
   <xsd:complexType name="BrandReturn">

    <xsd:all>
     <xsd:element name="errorCode" type="xsd:int"/>
     <xsd:element name="errorMessage" type="xsd:string"/>
     <xsd:element name="brandlist" type="tns:BrandsArray"/>
    </xsd:all>
   </xsd:complexType>
  </xsd:schema>
 </types>
 <message name="getbrandlistRequest">

  <part name="datasent" type="tns:brandlistReqData"/>
 </message>
 <message name="getbrandlistResponse">
  <part name="return" type="tns:BrandReturn"/>
 </message>
 <portType name="GetbrandlistwsdlPortType">
  <operation name="getbrandlist">
   <input message="tns:getbrandlistRequest"/>
   <output message="tns:getbrandlistResponse"/>

  </operation>
 </portType>
 <binding name="GetbrandlistwsdlBinding" type="tns:GetbrandlistwsdlPortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="getbrandlist">
   <soap:operation soapAction="urn:Getbrandlistwsdl" style="rpc"/>
   <input>
    <soap:body use="encoded" namespace="urn:Getbrandlistwsdl"
     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </input>

   <output>
    <soap:body use="encoded" namespace="urn:Getbrandlistwsdl"
     encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
   </output>
  </operation>
 </binding>
 <service name="getBrandList">
  <documentation>Return 3 character code and name of brands</documentation>
  <port name="GetbrandlistwsdlPort" binding="tns:GetbrandlistwsdlBinding">

   <soap:address
    location="https://www.mycompany.com/wwiz.asp?wwizmstr=XML.WEB.SERVICES"/>
  </port>
 </service>
</definitions>



I am unsure if the WSDL is correct , but I was able to use SOAPUI 1.7.6 , a java app,
to connect , input the data for the 4 strings and then get a successful return.
All I get when I try the php client is an error
Code:

HTTP Error: Unsupported HTTP response status 405 Method not allowed (soapclient->response has contents of the response)


client

Code:

<?php
require_once('./lib/nusoap.php');
$client = new nusoap_client("http://www.mycompany.com/soap", false);
$err = $client->getError();
if ($err) {
   echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
   echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
   exit();
}
//below are the definitions
$brandlistReqData = array(
    'xmlUser' => '1',
    'xmlPassword' => '2',
    'serviceName' => '3',
    'serviceMode' => '4'
);
$params = array('datasent' =>
            new soapval('datasent',
                        'getbrandlist',
                        $brandlistReqData,
                        false,
                        'http://mycompany.com/soap')
            );
$result = $client->call('getbrandlist', $params, 'datasent','urn:Getbrandlistwsdl', 'this_is_header_env');
if ($client->fault) {
   echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>';
} else {
   $err = $client->getError();
   if ($err) {
      echo '<h2>Error</h2><pre>' . $err . '</pre>';
   } else {
      echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';
   }
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
?>


I was actually trying to do this with excel, but couldn't be done.
Very new to this.
can anyone help point me in the right direction as to the structure of correct code for the client.
Thank You Question
View user's profileFind all posts by trini00Send private message
Client Issue (Resolved)


Joined: 16 Dec 2007
Posts: 5
Reply with quote
Finally got the client to work.
Before , I was trying to serialize the envelope and use nusoap at the same time.
First I included the libs for Nusoap, then
I let nusoap read and then cache the wsdl and then hard code the parameters into the client.
Code:

require_once('lib/nusoap.php');
require_once('lib/class.wsdlcache.php');

I invoked the client and it returned the response array successfully.
Code:

$result = $client->call('getbrandlist', $datasent);

This was actually simpler than what I was doing before.
/*
Does anyone know if its possible to hard code a constant into the WSDL so the client
doesn't need to pass it?
*/
Thanks.
Still learning about this stuff . Wink
View user's profileFind all posts by trini00Send private message
PHP Soap Client Help
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic