Search code examples
phpweb-servicessoapwsdl

PHP SOAP request not working with WSDL


I'm trying to use a SOAP service called Chaverweb. I have their WSDL; it's here.

When I try to make a simple request like GetCWVersion, it's working, but whenever I try to request a function that would need some sort of authentication, like Get_Syn_Comsend (getting an institute's details), it doesn't work.

I tried setting AuthHeader as specified in the WSDL, but it's not working.

Here's my code. I'm hoping there's something obvious I'm not doing since this is my first time working with SOAP:

try {
    $soapClient = new SoapClient('https://www.chaverweb.net/Synagogue.asmx?WSDL');
    $header = new SoapHeader('https://www.chaverweb.net/webservices/', 'AuthHeader', array("Username"=>"[email protected]", "Password"=>"...", "SynKey"=>"..."), false);
    $header2 = new SoapHeader('https://www.chaverweb.net/webservices/', 'SFHeader', array("sf"=>""), false);


    $soapClient->__setSoapHeaders(array($header, $header2));
    $versionResponse = $soapClient->Get_Syn_Comsend();
    print_r($versionResponse);
} catch (SoapFault $exception) {
    echo "Exception: " . $exception->getMessage();
}

This, by the way, gives me: stdClass Object ( ) Thank you very much!


Solution

  • so I did some direct testing and it is very simple:

    INVALID LOGIN is being returned on the WSDL.

    http://phpfiddle.org/main/code/3pvp-8wi9

    You can view my code and testing here. While you are testing use their bulit in TestFunction() instead of the function you want to run, this way you can see where the error is. Let me know how I can be of more assistance.

    BEFORE EDIT, THIS WAS MY RESPONSE:

    You first need to make sure that the last request you sent to complete the function has no errors. As well check that the response was received. This may help debug why you are getting this to begin with. Just add these two lines of code and let us know what you see:

    print_r($soapClient->__getLastRequest());
    print_r($soapClient->__getLastResponse());
    

    The key here is to make sure you are receiving the response correctly. Post this response and I will gladly help you debug it.

    Just food for thought, here is how I would set up this request (this is NOT tested) but the definition in your wsdl shows you need to be using literal and SoapClient does not always use the correct document type when interpreting the response:

    ini_set("soap.wsdl_cache_enabled", "0");
    try {
    $options = array('trace'=>1,
                     'exceptions'=> 1,
                     'style'=> SOAP_DOCUMENT,
                     'use'=> SOAP_LITERAL 
                    ); 
    
    $soapClient = new SoapClient('https://www.chaverweb.net/Synagogue.asmx?WSDL',$options);
    $header = new SoapHeader('https://www.chaverweb.net/webservices/', 'AuthHeader', array("Username"=>"[email protected]", "Password"=>"demo1234!", "SynKey"=>"T21982011213"), false);
        $header2 = new SoapHeader('https://www.chaverweb.net/webservices/', 'SFHeader', array("sf"=>""), false);
    
    
        $soapClient->__setSoapHeaders(array($header, $header2));
        $versionResponse = $soapClient->Get_Syn_Comsend();
    
        print_r($versionResponse->Get_Syn_ComsendSoapOut);
    
        } catch (SOAPFault $f) {
         print $f;
        }
    

    Hope this helps in some way! Send your results for further assistance :)

    POST EDIT FOR SIMPLEXML TEST: replace:

    print_r($versionResponse->Get_Syn_ComsendSoapOut);
    

    with this:

    $data = simplexml_load_file($versionResponse->Get_Syn_ComsendSoapOut);
    print_r($data);
    

    See what it gives you, hopefully it either throws a descriptive error or it processes the result (very rare, but possible)!