Need help debugging a very basic PHP SOAP Hello world app

Posted by WarDoGG on Stack Overflow See other posts from Stack Overflow or by WarDoGG
Published on 2010-05-03T10:54:49Z Indexed on 2010/05/03 10:58 UTC
Read the original article Hit count: 352

Filed under:
|
|
|

I have been breaking my head at this, reading almost every article and tutorial there is on the web, but nothing doing.. i still cannot get my first web service application to work.

I would really appreciate it if anyone could debug this code for me and provide me with a good explanation as to what is wrong and why. This will help indeed ! Thanks !

I have pasted below the entire codes that i am using making it easier to debug. I'm using the PHP5 SOAP extension.

Here is my WSDL:

    <?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="testWebservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s1="http://microsoft.com/wsdl/types/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
      <s:import namespace="http://microsoft.com/wsdl/types/" />
      <s:element name="getUser">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="username" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>

      <s:element name="getUserResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="getUserResult" type="tns:userInfo" />
          </s:sequence>
        </s:complexType>
      </s:element>

      <s:complexType name="userInfo">
        <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="ID" type="s:int" />
          <s:element minOccurs="1" maxOccurs="1" name="authkey" type="s:int" />
        </s:sequence>
      </s:complexType>

    </s:schema>
  </wsdl:types>

  <wsdl:message name="getUserSoapIn">
    <wsdl:part name="parameters" element="tns:getUser" />
  </wsdl:message>
  <wsdl:message name="getUserSoapOut">
    <wsdl:part name="parameters" element="tns:getUserResponse" />
  </wsdl:message>

  <wsdl:portType name="testWebservice">
    <wsdl:operation name="getUser">
      <wsdl:input message="tns:getUserSoapIn" />
      <wsdl:output message="tns:getUserSoapOut" />
    </wsdl:operation>
  </wsdl:portType>


  <wsdl:binding name="testWebserviceBinding"
    type="tns:testWebservice">

    <soap:binding style="document"
        transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="getUser">

        <soap:operation soapAction="http://tempuri.org/getUser" />
        <wsdl:input>
            <soap:body use="literal" />
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal" />
        </wsdl:output>
    </wsdl:operation>


  </wsdl:binding>

  <wsdl:service name="testWebserviceService">
    <wsdl:port name="testWebservicePort" binding="tns:testWebserviceBinding">
        <soap:address location="http://127.0.0.1/nusoap/storytruck/index.php" />
    </wsdl:port>
  </wsdl:service>

</wsdl:definitions>

and here is the PHP Code i use to setup the server:

<?php

    function getUser($user,$pass) {
        return array('ID'=>1);
    }

    ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
    $server = new SoapServer("http://127.0.0.1/mywsdl.wsdl");
    $server->addFunction('getUser');
    $server->handle();

?> 

and the code for the client:

<?php

    $client = new SoapClient("http://127.0.0.1/index.php?wsdl", array('exceptions' => 0));

    try {
        $result = $client->getUser("username","pass");
        print_r($result);
    }
    catch (SoapFault $result) {
        print_r($result);
    }

?> 

Here is the ERROR output i am getting on the browser :

SoapFault Object
(
    [message:protected] => Error cannot find parameter
    [string:Exception:private] => 
    [code:protected] => 0
    [file:protected] => C:\xampp\htdocs\client.php
    [line:protected] => 6
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [function] => __call
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => getUser
                            [1] => Array
                                (
                                    [0] => username
                                    [1] => pass
                                )

                        )

                )

            [1] => Array
                (
                    [file] => C:\xampp\htdocs\client.php
                    [line] => 6
                    [function] => getUser
                    [class] => SoapClient
                    [type] => ->
                    [args] => Array
                        (
                            [0] => username
                            [1] => pass
                        )

                )

        )

    [previous:Exception:private] => 
    [faultstring] => Error cannot find parameter
    [faultcode] => SOAP-ENV:Client
)

© Stack Overflow or respective owner

Related posts about php

Related posts about soap