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 视频编码 十六进制问题
  • ¥15 Xsheii7我安装这个文件的时候跳出来另一个文件已锁定文件的无一部分进程无法访问。这个该怎么解决
  • ¥15 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式