PHPはWebserviceの考え方とソースの共有を呼び出します。
<?
/******************************************************************************/
/* : soapclient.php
/* : WebService
/******************************************************************************/
include('NuSoap.php');
// soapclient , server WSDL
$client = new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl');
//
$aryPara = array('strUsername'=>'username', 'strPassword'=>MD5('password'));
//
$aryResult = $client->call('login',$aryPara);
//echo $client->debug_str;
/*
if (!$err=$client->getError()) {
print_r($aryResult);
} else {
print "ERROR: $err";
}
*/
$document=$client->document;
echo <<<SoapDocument
<?xml version="1.0" encoding="GB2312"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
$document
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SoapDocument;
?>
<?
/******************************************************************************/
/* : soapclient.php
/* : WebService
/******************************************************************************/
include('NuSoap.php');
// soapclient , server WSDL
$client = new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl');
//
$aryPara = array('strUsername'=>'username', 'strPassword'=>MD5('password'));
//
$aryResult = $client->call('login',$aryPara);
//echo $client->debug_str;
/*
if (!$err=$client->getError()) {
print_r($aryResult);
} else {
print "ERROR: $err";
}
*/
$document=$client->document;
echo <<<SoapDocument
<?xml version="1.0" encoding="GB2312"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
$document
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SoapDocument;
?>
方法二:プロキシ方式の呼び出し
<?
/******************************************************************************/
/* : soapclient.php
/* : WebService
/******************************************************************************/
require('NuSoap.php');
// soapclient , server WSDL
$client=new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl');
// proxy
$proxy=$client->getProxy();
//
$aryResult=$proxy->login('username',MD5('password'));
//echo $client->debug_str;
/*
if (!$err=$proxy->getError()) {
print_r($aryResult);
} else {
print "ERROR: $err";
}
*/
$document=$proxy->document;
echo <<<SoapDocument
<?xml version="1.0" encoding="GB2312"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
$document
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SoapDocument;
?>
<?
/******************************************************************************/
/* : soapclient.php
/* : WebService
/******************************************************************************/
require('NuSoap.php');
// soapclient , server WSDL
$client=new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl');
// proxy
$proxy=$client->getProxy();
//
$aryResult=$proxy->login('username',MD5('password'));
//echo $client->debug_str;
/*
if (!$err=$proxy->getError()) {
print_r($aryResult);
} else {
print "ERROR: $err";
}
*/
$document=$proxy->document;
echo <<<SoapDocument
<?xml version="1.0" encoding="GB2312"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
$document
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SoapDocument;
?>
多くはNuSoapを使用しています。NET WebServiceまたはJ 2 EE WebServiceの友達は中国語の文字化けの問題に会ったことがあるかもしれません。この問題の発生原因と解決方法を紹介します。NuSoapがWebServiceを呼び出して文字化けが発生した理由:通常WebServiceの開発に使うUTF-8コードです。この時に設定が必要です。
$client->soap_defencoding = 'utf-8';
$client->soap_defencoding = 'utf-8';
同時に、xmlに同じ符号化方式で伝達させる必要があります。
$client->xml_encoding = 'utf-8';
$client->xml_encoding = 'utf-8';
はこれですべて正常になるはずです。しかし、私達は結果を出力する時、戻ってくるのは文字化けです。NuSoapがWebServiceを呼び出して文字化けの解決方法が現れます。実際にデバッグ機能を開いた友達は、client->reponseが戻ってきたのが正しい結果だと信じています。どうしてresult=$client->call($action、array('parameters');param);文字化けですか?NuSoapコードを検討したら、xml_encodingをUTF-8に設定すると、NuSoapはdecode_を検出します。utf 8の設定は、trueであればPHP内のutf 8_を実行します。decode関数、NuSoapはデフォルトでtrueですので、設定が必要です。
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'utf-8';
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'utf-8';