5

I have a web service and I am calling one of its operations using SOAP client in PHP but all I get is this ["any"]=> string(120) "falseObject reference not set to an instance of an object.

I want to know is there anything wrong in my code because I belive that my connection to the web service is %100 working.

Is there anything wrong in the xml string that I am creating ?

The operation is :

<wsdl:operation name="XmlIslet">
    <wsdl:input message="tns:XmlIsletSoapIn"/>
    <wsdl:output message="tns:XmlIsletSoapOut"/>
</wsdl:operation>

and the description of its parameters in the WSDL is :

<wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
        <s:element name="XmlIslet">
            <s:complexType>
                <s:sequence>
                    <s:element minOccurs="0" maxOccurs="1" name="xmlIslem">
                        <s:complexType>
                            <s:sequence>
                                <s:any/>
                            </s:sequence>
                        </s:complexType>
                    </s:element>
                    <s:element minOccurs="0" maxOccurs="1" name="xmlYetki">
                        <s:complexType>
                            <s:sequence>
                                <s:any/>
                            </s:sequence>
                        </s:complexType>
                    </s:element>
                </s:sequence>
            </s:complexType>
        </s:element>
        <s:element name="XmlIsletResponse">
            <s:complexType>
                <s:sequence>
                    <s:element minOccurs="0" maxOccurs="1" name="XmlIsletResult">
                        <s:complexType mixed="true">
                            <s:sequence>
                                <s:any/>
                            </s:sequence>
                        </s:complexType>
                    </s:element>
                </s:sequence>
            </s:complexType>
        </s:element>
    </s:schema>
</wsdl:types>

My soap and PHP code is the following :

<?php
$username = "username";
$password = "password";
$xmlString = "<Firmalar></Firmalar>";

function strtoXmldocument($str)
{
    $dom = new DOMDocument();
    $str1 = $str;
    return $dom->loadXML($str1);
}

function stringToDataset($xmlString, $username, $password)     
{                       
    $client = new SoapClient('http://1.1.1.1/WSTEST/Service.asmx?WSDL');

    $response = $client->XmlIslet(strtoXmldocument($xmlString)->documentElement,  
strtoXmldocument("<Kullanici><Adi>" .$username. "</Adi><Sifre>" .$password. "</Sifre></Kullanici>")->documentElement);

var_dump($response);
}

stringToDataset($xmlString, $username, $password);
?>

The SOAP request is as the following:

POST /WSTEST/Service.asmx HTTP/1.1
Host: 1.1.1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <XmlIslet xmlns="http://tempuri.org/">
      <xmlIslem>xml</xmlIslem>
      <xmlYetki>xml</xmlYetki>
    </XmlIslet>
  </soap12:Body>
</soap12:Envelope>

The SOAP response :

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

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <XmlIsletResponse xmlns="http://tempuri.org/">
      <XmlIsletResult>xml</XmlIsletResult>
    </XmlIsletResponse>
  </soap12:Body>
</soap12:Envelope>

vardump output is :

usernamepasswordobject(stdClass)#2 (1) { ["XmlIsletResult"]=> object(stdClass)#3 (1) { ["any"]=> string(120) "falseObject reference not set to an instance of an object." } } 

EDIT : I tried to get the request xml using htmlentities($client->__getLastRequest()) which shows me an empty body of my request :

========= REQUEST ========== 
string(292) 
"<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:XmlIslet>
<ns1:xmlIslem/>
<ns1:xmlYetki/>
</ns1:XmlIslet>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope> "
Basel
  • 1,305
  • 7
  • 25
  • 34
  • maybe the object doesnt exist – Rico Apr 11 '17 at 13:44
  • use in xml to check if xml was incorrectly formed – Rico Apr 11 '17 at 13:49
  • since response has 200 it means everything is proper but u r reading a property for object that is null – Rico Apr 11 '17 at 13:50
  • @Rico which object? I check the connection it is working and not throwing any error and then I call the operation `$client->XmlIslet` – Basel Apr 11 '17 at 13:51
  • @Rico I used this `if (is_soap_fault($response)) { trigger_error("SOAP Fault: (faultcode: {$response->faultcode}, faultstring: {$response->faultstring})", E_USER_ERROR);` and it does not throw any error – Basel Apr 11 '17 at 13:52
  • http://stackoverflow.com/questions/24574716/object-reference-not-set-to-an-instance-of-an-object-error-when-trying-soap-call?rq=1 – Rico Apr 11 '17 at 18:14
  • @Rico Actually I tried `SoapVar` but it still gives the same error message, Do you think I am passing the xml parameters in the right format? and by the way what is the meaning of `` in the WSDL mentioned inside the parameters – Basel Apr 14 '17 at 05:26
  • wow u set a bounty, can u tell me what the request xml looks like, so i can make one for you – Rico Apr 14 '17 at 09:45
  • in xml tag is used for adding something which is not defined already. like https://www.w3schools.com/xml/schema_complex_any.asp the person is defined with firstname and lastname but then it has a any tag so u can add any other thing to person when you use it elsewhere like they added – Rico Apr 14 '17 at 09:56
  • check this http://php.net/manual/en/soapclient.getlastrequest.php this will print the xml that u sent – Rico Apr 14 '17 at 10:05
  • Hi @Basel. Can you provide URL to WSDL definition? – rock3t Apr 15 '17 at 07:46

1 Answers1

0

You're most likely communicating with a .NET service. This error message is basically a "variable undefined" message.

The WSDL file says, you request must contain two entities: xmlIslem and xmlYetki. But their internal structure is not properly defined, it can be "any"-thing. This, however, doesn't mean, that the remove web service doesn't expect you to provide some data. It looks like you need to pass some data, which you don't, hence the error.

I would contact the web service provider and requested the documentation or specific request examples.

Viktoras
  • 53
  • 8
  • what does this line do strtoXmldocument("" .$username. "" .$password. "")->documentElement); o.O – Rico Apr 16 '17 at 20:20
  • @Rico it is supposed to parse an XMLstring to a XMLDOM Obj, however while it has invalid XML it wont work, it supposed to have the ` – Barkermn01 Apr 20 '17 at 11:03