0

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...

3
  • Are you sure this byte array you get is an .NET object? It simply does not make sense for the service to do this. You would need a .NET dll containing this type to deserialize it. What would be the methods of that type and what would you want to do with it? Commented Feb 4, 2014 at 14:36
  • Ya.. 100% sure. From that array I want to access the variables in that for perticuler checks of licensing. Commented Feb 5, 2014 at 5:12
  • If You have Any wsdl that returns pure xml, please share it with me.. I just want to test that if I get the return data in xml then is that possible to access it via PHP as an object or Not.. So that I can Inform my web service provider to return data in xml format. Commented Feb 5, 2014 at 5:56

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.