2017-03-17 16 views
1

私はこのトラックの初心者なので、簡単なPHP Webサービスを作成しようとしています。 SOAPを使って開発することにしました。私はWAMPをサーバーとして使用していますが、問題はスクリプトを実行したり、WSDLファイルを取得できないことです。ここでPHP SOAP Webサービス

はserver.phpというのコードです:

<?php 
//call library 
require_once ('lib/nusoap.php'); 
//using soap_server to create server object 
$server = new soap_server; 

//register a function that works on server 
$server->register('get_message'); 

// create the function 
function get_message($your_name) 
{ 
if(!$your_name){ 
return new soap_fault('Client','','Put Your Name!'); 
} 
$result = "Hello World ".$your_name .". Thanks for Your First Web Service Using PHP with SOAP"; 
return $result; 
} 
// create HTTP listener 
$server->service($HTTP_RAW_POST_DATA); 
exit(); 
?> 

、ここでは、実行のスクリーンショットです:

running server.php

ここclient.phpのコードだ:

<?php 
require_once ('lib/nusoap.php'); 
//Give it value at parameter 
$param = array('your_name' => 'Omar'); 
//Create object that referer a web services 
$client = new soapclient('http://localhost/WebServiceSOAP/server.php'); 
//Call a function at server and send parameters too 
$response = $client->call('get_message',$param); 
//Process result 
if($client->fault) 
{ 
echo "FAULT: <p>Code: (".$client->faultcode."</p>"; 
echo "String: ".$client->faultstring; 
} 
else 
{ 
echo $response; 
} 
?> 

とここです実行のスクリーンショット:

running client.php enter image description here

プラスこのエラーは私を悩ませ続けて:

未定義の変数:HTTP_RAW_POST_DATA

答えて

0

をuは

$client = new SoapClient(
    null, 
    array(
     'location' => 'ADD YOUR LOCATION', 
     'uri' => 'ADD YOUR WSDL FILE ', 
     'trace' => 1, 
     'use' => SOAP_LITERAL, 
    ) 
); 
にコード

$client = new soapclient('http://localhost/WebServiceSOAP/server.php'); 

以下、これを試すことができます

+0

おかげで、私は私自身のWSDLファイルを追加する必要はありません:あなたは、代わりに私はこのようにそれを行うことを提案することのhere

を読むことができます。代わりに、J2EEのように生成します。 – user3090933

0

未定義の変数$HTTP_RAW_POST_DATAを使用しようとしています。 PHP7では、このフックは削除されています。あなたの助けのための

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

返信いただきありがとうございますが、wsdlファイルは表示されません。 – user3090933

+0

はい、SOAP原則を転送する必要があります。 WSDLはそのスタンダードのためのポイントを持っている必要があります。 PHPについては、http://php.net/manual/en/book.soap.phpを参照してください。 –

関連する問題