简体   繁体   中英

Problem consuming WCF web service with php / nuSoap

I have 3 client sites that all rely on an external webservice. The webservice used to be on a ColdFusion server, but it has just changed over to a .NET server. My client code no longer works, and I am not having any luck fixing it. The client sites are on php and use nusoap to call the webservice.

I set up this test, using the wsdl like I used to do it:

<?php
// Call the nuSOAP library 
require_once('/home/realtywest/www/lib/nusoap.php');

// Create the client instance
$client = new soapclientnusoap('http://webservices.reiwa.com/RMHPServices/ListingsService.svc?wsdl', true);

// Check for an error
$err = $client->getError();
if ($err) {
    // Display the error
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    // At this point, you know the call that follows will fail
}

// Call the SOAP method
$result = $client->call('getListingDetail', array('ListingNumber' => 3000975));

// Check for a fault
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        echo '<h2>Result</h2><pre>';
        print_r($result);
    echo '</pre>';
    }
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>

The results of that script can be see here: http://www.realtywest.com.au/listings/test_wsdl.php

That returns an internal service fault..

I googled my issue and found this really old forum post: http://www.sitepoint.com/forums/showthread.php?t=97632 where they suggested that sometimes .NET webservices are set up differently, and not to pass it into nusoap as wsdl, also when calling to actually pass in the request and not just an array of variables..

so I tried this way:

<?php
// Call the nuSOAP library 
require_once('/home/realtywest/www/lib/nusoap.php');

// Create the client instance
$client = new soapclientnusoap('http://webservices.reiwa.com/RMHPServices/ListingsService.svc', false);

// Check for an error
$err = $client->getError();
if ($err) {
    // Display the error
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    // At this point, you know the call that follows will fail
}

// Call the SOAP method
$result = $client->call('getListingDetail', '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:getListingDetail>
         <!--Optional:-->
         <tem:strListingNumber>3000975</tem:strListingNumber>
      </tem:getListingDetail>
   </soapenv:Body>
</soapenv:Envelope>');

// Check for a fault
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        echo '<h2>Result</h2><pre>';
        print_r($result);
    echo '</pre>';
    }
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>

See here: http://www.realtywest.com.au/listings/test.php this time a get an Action Not supported error.. The request sent through in the second message was copied from SOAP UI where I can actually get results, so I know that the web service does indeed work..

I'm sure someone can look at the debug messages and know what the problem is.. I would really appreciate any help on this one..

Try setting your encoding to utf-8. nusoap defaults to ISO-8859-1. I'm not a php developer but I have done the wcf.net to php thing a while back, and that was a gotcha I ran into.

$wsdl="http://webservices.reiwa.com/RMHPServices/ListingsService.svc?wsdl";
$client=new soapclient($wsdl, 'wsdl');
$client->soap_defencoding = 'utf-8';//default is 
$client->response_timeout = 60;//seconds

//paramaters to the webservice
$param=array('ListingNumber' => 3000975);

//the function within the service to call
$result = $client->call('getListingDetail', $param);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM