Page 1 of 1

Referencing Previous Phalanger Variables Passed From C#

PostPosted: October 5th, 2014, 5:25 pm
by MX26
Hi there,

I have a bit of code that runs like this in a C# class:
Code: Select all
dynamic response = PhalangerClass.GetResponse(variable);
dynamic testResult = PhalangerClass.TestResult(response);


GetResponse and TestResult are functions written in PHP and compiled using Pure Mode Phalanger.

The variables appear to pass successfully with one issue. Within PhalangerClass.TestResult, when I scope the $response variable, the variable consists of a binary component and a string component. I wish to reference the string component of the variable as the binary component is not compatible with the TestResult function.

Is there a way to accomplish this?

Thanks!

Re: Referencing Previous Phalanger Variables Passed From C#

PostPosted: October 5th, 2014, 9:29 pm
by Jakub Misek
What is the type of response variable?

Re: Referencing Previous Phalanger Variables Passed From C#

PostPosted: October 5th, 2014, 10:10 pm
by MX26
Jakub,

The response variable is a string containing HTML from a web page response. The intention is to pass the string to the next Phalanger function for a parsing operation.

Re: Referencing Previous Phalanger Variables Passed From C#

PostPosted: October 5th, 2014, 10:25 pm
by Jakub Misek
If it is a string, it is passed in the same form into the next function. Try to put watch onto the C# variable response and look on its type.

Re: Referencing Previous Phalanger Variables Passed From C#

PostPosted: November 5th, 2014, 1:44 am
by MX26
Jakub,

Inspection of the variables within the PHP script reveals that they are an array. The first array index contains an array of binary. The second array index contains the string that I am looking for. The names of the array indices are 'Binary' and 'String', respectively. Attempting to pass the variable's [String] index to the main C# program only yields a variable containing bytes.

Thanks.

Re: Referencing Previous Phalanger Variables Passed From C#

PostPosted: November 5th, 2014, 1:49 am
by MX26
Easy fix. I was able to simply convert the byte array within the C# calling program by using:

string result = System.Text.Encoding.UTF8.GetString(byteArray);

Another one for the records.