给梦一个奔跑的方向!
PDF Print E-mail
User Rating: / 0
PoorBest 
Written by xlingfairy
Saturday, 06 February 2010 12:32
 先说说我前面遇到的挫折:
复杂类型 与 数组.
这个问题困扰我好几天了, C# 写的 client 在请求SOAP方法之后,报错:
 
soap 未识别指定的类型: name='struct'
这个 struct 可能是其它的,你在PHP里定义的类.
 
解决办法是,指定 style 为 literal , 默认的为: encoded , 参见:
http://framework.zend.com/manual/en/zend.soap.autodiscovery.html
这个页面最下面的代码框里有写.
 
include 'common.php';
$loader->registerNamespace ( "Joomla" );
 
if (isset ( $_GET ['wsdl'] )) {
$autodiscover = new Zend_Soap_AutoDiscover ( 'Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence' );
$autodiscover->setOperationBodyStyle ( array ('use' => 'literal', 'namespace' => 'http://www.fuqilia.com' ) );
$autodiscover->setClass ( 'Joomla_User' );
$autodiscover->handle ();
exit ();
} else {
ini_set("soap.wsdl_cache_enabled", "0");
$soap = new Zend_Soap_Server ( URL . "/?wsdl"); // this current file here
$soap->setClass ( 'Joomla_User' );
$soap->handle ();
}
 
上面的 namespace 必须有.
另外,如果用的是  Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex 的话, 在C# 里 client 得到的结果不能解析为 User (C#里,会自动根据WSDL生成一个User) 类.
 
Joomla_User 的定义:
--------------------------
<?php
class User{
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $sex;
public function __construct($name , $sex){
$this->name = $name;
$this->sex = $sex;
}
}
 
class UserCollection{
/**
* @var User[]
*/
public $users = array();
}
 
class Joomla_User{
/**
* @return User[]
*/
public static function ListUser(){
$users = array();
$users[] = new User('xling','male');
$users[] = new User('snow','female');
/* $uc = new UserCollection();
$uc->users = $users;*/
return $users;
}
/**
* @return string[]
*/
public static function GetUser(){
return array('xling','snow');
}
/**
* @return User
*/
public static function GetUser2(){
return new User('xling','male');
}
}
?>
 
 
C# 调用代码:
 
Joomla.Joomla_UserService client = new PluginTest.Joomla.Joomla_UserService();
client.ListUserCompleted += new PluginTest.Joomla.ListUserCompletedEventHandler(client_ListUserCompleted);
client.ListUserAsync();
Joomla.User uss1 = client.GetUser2();
string[] names1 = client.GetUser();
Last Updated ( Saturday, 06 February 2010 12:42 )
 

Add comment


Security code
Refresh

Popular Contents

Recommend

Site Info

Members : 1
Content : 100
Web Links : 7
Content View Hits : 56182

Links