douzhi7451 2014-02-04 14:00
浏览 41
已采纳

使用COM从PHP反序列化.Net对象

I have a .net Web service Method 'CheckCustomerLicense', and this method returns a C sharp serialized object, I am calling this method via Soap from PHP.

I am getting the serialized object which is binary formatted and not in XML.

I want to access that data as object in PHP, but to do this I must desirealize it, and since its a .NET object I want to use .NET built in class 'System.Runtime.Serialization.Formatters.Binary.BinaryFormatter' via COM.

The Code I am Using For This Is Shown Below:

<?php
class eToolsLicenseNew
{
} 

$url='http://mail.ucm.com.au/eToolsLicenseWebService/eToolsLicenseWebUpdateService.asmx?WSDL';
$soap = new SoapClient($url, array(
"trace" => 1,           // enable trace to view what is happening 
"exceptions" => 1,      // disable exceptions "cache_wsdl" => 1)
 );

 try {
 $customer=array('customerId'=>'12345');
$result=$soap->CheckCustomerLicense($customer);
//print_r($result);

$obj = new COM("System.Runtime.Serialization.Formatters.Binary.BinaryFormatter");
$object=new eToolsLicenseNew();
 $object=$obj->Deserialize($result); // call to deserilize method
}
catch (SoapFault $e)
 { 
echo "Error: {$e->faultstring}";
 }
 ?>

But When I call 'Deserializing Method' Giving Internal Server Error.... Other than that every thing is fine, Can Any one is there to help me... Please...

  • 写回答

1条回答 默认 最新

  • dshfjsh_5455 2014-02-05 09:45
    关注

    The data your receive is a byte array. If it contains a .NET binary formatted object, you will need to have a BinaryFormatter to deserialize it. A binary formatters Deserialize method however, does not take a byte array. It takes a stream of any kind. The simplest conversion method from byte array to a stream is using a MemoryStream. This takes a byte array as constructor parameter.

    var bytes = new byte[50]; // example byte array
    
    using(var stream = new MemoryStream(bytes))
    {
        BinaryFormatter formatter = new BinaryFormatter();
        var obj = (YourExpectedType)formatter.Deserialize(stream);
    }
    

    This is what the C# code would look like, you will need to adapt it to the COM/PHP variant.

    Again, if this is really the case, someone is sending a binary serialized object via XML serialized SOAP to someone, then the first someone needs to learn how to code webservices. Because this is not an interoperable webservice, this is C#-to-C# communication wasting time using SOAP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测