2016-10-14 30 views
5

Nusoap kullanarak basit bir web servis uygulamasını uygulamaya çalışıyorum. Sunucu:Nusoap "SOAP-ENV: Xml boştu, ayrıştırılmadı" İleti

<?php 
require_once "nusoaplib/nusoap.php"; 

class food { 

    public function getFood($type) { 
     switch ($type) { 
      case 'starter': 
       return 'Soup'; 
       break; 
      case 'Main': 
       return 'Curry'; 
       break; 
      case 'Desert': 
       return 'Ice Cream'; 
       break; 
      default: 
       break; 
     } 
    } 
} 

$server = new soap_server(); 
$server->configureWSDL("foodservice", "urn:foodservice"); 

$server->register("food.getFood", 
    array("type" => "xsd:string"), 
    array("return" => "xsd:string"), 
    "urn:foodservice", 
    "urn:foodservice#getFood", 
    "rpc", 
    "encoded", 
    "Get food by type"); 

@$server->service($HTTP_RAW_POST_DATA); 
?> 

Müşteri:

<?php 
require_once "nusoaplib/nusoap.php"; 

$client = new nusoap_client("http://localhost/SOAPServer.php?wsdl", true); 
$error = $client->getError(); 

if ($error) { 
    echo "<h2>Constructor error</h2><pre>" . $error . "</pre>"; 
} 

$result = $client->call("food.getFood", array("type" => "Main")); 

if ($client->fault) { 
    echo "<h2>Fault</h2><pre>"; 
    print_r($result); 
    echo "</pre>"; 
} else { 
    $error = $client->getError(); 
    if ($error) { 
     echo "<h2>Error</h2><pre>" . $error . "</pre>"; 
    } else { 
     echo "<h2>Main</h2>"; 
     echo $result; 
    } 
} 

// show soap 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>"; 
?> 

WSDL dosyası aşağıdaki olan, NuSOAP ile oluşturulur:

<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="urn:foodservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:foodservice"> 
<types> 
<xsd:schema targetNamespace="urn:foodservice"> 
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> 
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/> 
</xsd:schema> 
</types> 
<message name="food.getFoodRequest"> 
<part name="type" type="xsd:string"/> 
</message> 
<message name="food.getFoodResponse"> 
<part name="return" type="xsd:string"/> 
</message> 
<portType name="foodservicePortType"> 
<operation name="food.getFood"> 
<documentation>Get food by type</documentation> 
<input message="tns:food.getFoodRequest"/> 
<output message="tns:food.getFoodResponse"/> 
</operation> 
</portType> 
<binding name="foodserviceBinding" type="tns:foodservicePortType"> 
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
<operation name="food.getFood"> 
<soap:operation soapAction="urn:foodservice#getFood" style="rpc"/> 
<input> 
<soap:body use="encoded" namespace="urn:foodservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
</input> 
<output> 
<soap:body use="encoded" namespace="urn:foodservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> 
</output> 
</operation> 
</binding> 
<service name="foodservice"> 
<port name="foodservicePort" binding="tns:foodserviceBinding"> 
<soap:address location="http://10.152.128.39/SOAPServer.php"/> 
</port> 
</service> 
</definitions> 

sunucu dosya ve WSDL dosya hem erişme ikisi de çalışır, ancak istemciye erişmeye çalıştığımda hata iletisini alırım:

[faultcode] => SOAP-ENV:Client 
    [faultactor] => 
    [faultstring] => error in msg parsing: 
xml was empty, didn't parse! 
    [detail] => 

Herhangi bir öneri sorun ne olabilir?

cevap

13

Nuso'nuzda. Sunucu değiştirmek gerekir:

Bu:

@$server->service($HTTP_RAW_POST_DATA); 

Bunun için: Eğer uyarılar ve uyarıları kontrol etmek istiyorsanız

@$server->service(file_get_contents("php://input"));

Sen @ kaldırabilir.

http://php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data

Bu özellik bazı açıklama PHP 5.6.0 yılında KALDIRILDI ve PHP 7.0.0 itibariyle KALDIRILDIYSA. TRUE olarak ayarlanırsa, PHP her zaman ham POST verilerini içeren $ HTTP_RAW_POST_DATA'sını dolduracaktır. Aksi halde, değişken yalnızca verilerin MIME türü tanınmadığında doldurulur. // girişi ve $ HTTP_RAW_POST_DATA itibaren PHP 5.6.0 önerilmemektidir:

ham POST verilerine erişmek için tercih edilen bir yöntem php. Always_populate_raw_post_data değerini -1 olarak ayarlamak, HTTP_RAW_POST_DATA'nın hiçbir zaman tanımlanmadığı PHP'nin gelecekteki bir sürümünde uygulanacak yeni davranışı seçecektir.

Ayardan bağımsız olarak, $ HTTP_RAW_POST_DATA enctype = "multipart/form-data" ile kullanılamaz.

+0

Both @ $ server-> service (dosya_get_contents ("php: // input")) ile çalıştım;); ama işe yaramadı. daha sonra php.ini ayarını değiştirdim ve hep hala çalışmamasına rağmen always_populate_raw_post_data. Herhangi biri bana yardım edebilir. –

+0

@ $ server-> service (file_get_contents ("php: // input")); @ BantyRoy İstemcimi/sunucu çiftini indirip test ettim ve çalışıyor gibi görünüyor (köreliyorum). Sunucunuzda bazı yanlış yapılandırmalar veya sürümler veya başka bir şeyle ilgili başka bir sorun var gibi görünüyor. – erm3nda

+0

Teşekkür ederim erkekler, PHP 7.0'da mükemmel çalıştım, üç saat hata düzeltildi d :) –