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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!