首页 新闻 会员 周边

.NET WebService 参数为一个类的子类时, 父类属性不能传递的问题

0
悬赏园豆:20 [已关闭问题]

大家好:

    我的问题是这样的, 我用.NET写的WS中, 其中有一个参数为一个类(A), A类是另一个类(B) 的子类

    若用.NET调用这个WebService则没有任何问题, 现在使用PHP调用, 才发现在Soap中根本没有B类中的属性, 我还以为只是没有显示出来的问题, 于是调用时同样给B类中的属性进行了赋值, 但结果是B类中的参数不能被接收到.
    请问这该怎么进行处理啊? 谢谢大家

    qindgfly

问题补充: A继承于B, 并且都是可以序列化的(因为我使用了Remoting), 因此我希望只传递一个A的对象就好了, 我想同时将A和B作为Web方法不是最好的方法吧? 请看:[求助] .NET WebService 参数为一个类的子类时, 用PHP调用时父类属性不能传递的问题 http://social.microsoft.com/Forums/zh-CN/xmlwebserviceszhchs/thread/3854da71-3570-49f6-b3d6-983136213385/
东国先生的主页 东国先生 | 菜鸟二级 | 园豆:225
提问于:2009-08-06 18:55
< >
分享
其他回答(3)
0

A 类和B类都支持序列化吗?继承关系?

其次就是你Web服务的 方法如何写的?

不会同时使用两个类做参数吗?

Frank Xu Lei | 园豆:1860 (小虾三级) | 2009-08-06 19:30
0

序列化,你在B类中有继承了Iserializable接口了没有?

风浪 | 园豆:2996 (老鸟四级) | 2009-08-07 13:24
0

PHP偶还真不太清楚~不过不知道你是怎么用PHP调用WSの~传说直接调用可能会有问题,用代理调用似乎会好点~

e.g.

直接调用

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;

?>

成用代理调用

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;

?>

Gieno | 园豆:255 (菜鸟二级) | 2009-08-07 16:49
0

B类都有些什么东西,最好贴出代码来看看

排骨虾 | 园豆:401 (菜鸟二级) | 2009-08-07 17:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册