下面是我貼在 stackoverflow.com 發問的問題,後來我自己解掉了。
http://stackoverflow.com/questions/8737234/how-php-nusoap-client-transfer-complextype-to-net-soap-server
不想翻譯了…
總之,如果你有「使用 php 傳送 ComplexType 型態的參數到 web service 的需求」的話,那就花個半小時看一下這篇吧
I am trying to create a client soap call using php nusoap to an existing SOAP server build on .NET that contains complexTypes.
I want to call QueryTestCategory(see belows)
And it has param searchTag and Call_Result that are string
But param LGI is type of LoginInfo(struct LoginInfo { string User_Name; string Password; })
So,how do I setup the parameters for QueryTestCategory?
I perform a getTypes I receive the following
struct HelloWorld { }
struct HelloWorldResponse { string HelloWorldResult; }
struct QueryTestSuite { LoginInfo LGI; string searchTag; string Call_Result; }
struct LoginInfo { string User_Name; string Password; }
struct QueryTestSuiteResponse { ArrayOfSuiteInfo QueryTestSuiteResult; string Call_Result; }
struct ArrayOfSuiteInfo { SuiteInfo SuiteInfo; }
struct SuiteInfo { string Test_Suite_ID; string Test_Suite_Name; string Tag; string Owner; string Remark; }
struct QueryTestCategory { LoginInfo LGI; string searchTag; string Call_Result; }
struct QueryTestCategoryResponse { ArrayOfCategoryInfo QueryTestCategoryResult; string Call_Result; }
struct ArrayOfCategoryInfo { CategoryInfo CategoryInfo; }
struct CategoryInfo { string Test_Category_ID; string Test_Category_Name; string Tag; string Owner; string Remark; }
struct QueryTestCase { LoginInfo LGI; string searchTag; string Call_Result; }
struct QueryTestCaseResponse { ArrayOfTestCaseInfo QueryTestCaseResult; string Call_Result; }
struct ArrayOfTestCaseInfo { TestCaseInfo TestCaseInfo; }
struct TestCaseInfo { string Test_Case_ID; string Test_Case_Name; string Test_Case_Version; string Tag; string Entry_Point; string Test_Kit_Name; string Test_Kit_Version; string Extra_Parameter; string Estimate_Time; string Function_Team; string Remark; string Test_Log_Parser_Name; string Test_Log_Parser_Version; string Test_Log_Parser_Entry_Point; string Test_Log_Parser_Extra_Parameter; string Owner; }
struct QueryTestResult { LoginInfo LGI; string TaskID; string Call_Result; }
struct QueryTestResultResponse { string QueryTestResultResult; string Call_Result; }
I try this, but it fails
/*
* $Id: wsdlclient1.php,v 1.3 2007/11/06 14:48:48 snichol Exp $
*
* WSDL client sample.
*
* Service: WSDL
* Payload: document/literal
* Transport: http
* Authentication: none
*/
require_once('lib/nusoap.php');
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
$client = new nusoap_client('http://www.example.com/Query.asmx?WSDL', 'wsdl',
$proxyhost, $proxyport, $proxyusername, $proxypassword);
$err = $client->getError();
if ($err) {
echo "Constructor error";
}
// Doc/lit parameters get wrapped
$param = array('User_Name' => 'SSD_WS_01', 'Password' => 'SSD_WS_01', 'searchTag' => 'test', 'Call_Result' => '');
$result = $client->call('QueryTestCategory', array('parameter' => $param), '', '', false, true);
// Check for a fault
if ($client->fault) {
print_r($result);
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo 'Error;
} else {
// Display the result
echo 'Result';
print_r($result);
}
}
I found ANSWER!
After reading this web page and many many other information
http://gznofeng.iteye.com/blog/951762
My finally code is like below
To sum up…
create $param1 = new stdClass,set parameter via $param1->varName = ‘something’
That all!
23 // Doc/lit parameters get wrapped
24 //$param1 = array('User_Name' => 'SSD_WS_01', 'Password' => 'SSD_WS_01');
25 $param1 = new stdClass();
26 $param1->User_Name = 'SSD_WS_01';
27 $param1->Password = 'SSD_WS_01';
28
29 $result = $client->call('QueryTestCategory', array('LGI' => $param1, 'searchTag' => '' ), '', '', false, true);
30 // Check for a fault
31 if ($client->fault) {
32 echo 'Fault
';
33 print_r($result);
34
35 } else {
36 // Check for errors
37 $err = $client->getError();
38 if ($err) {
39 // Display the error
40 echo 'Error
' . $err;
41 } else {
42 // Display the result
43 echo 'WoW,Result
';
44 print_r($result);
45
46 }
47 }
補充傳遞 array 的方法,看起來似乎 nusoap 本身沒有支援 arrayType
所以要自己額外把下面這段代碼加入才能支援 arrayType
$server->wsdl->addComplexType("ArrayOfString",
"complexType",
"array",
"",
"SOAP-ENC:Array",
array(),
array(array("ref"=>"SOAP-ENC:arrayType","wsdl:arrayType"=>"xsd:string[]")),
"xsd:string");
REF: http://www.linuxquestions.org/questions/programming-9/php-soap-server-returns-array-using-nusoap-library-600470/
然後就可以用下面這樣的陣列了
array("return" => "tns:ArrayOfString"),