Archives for April 2010

By value, by reference: by analogy

Here’s my best attempt to explain C# value types and reference types, and “pass by value” and “pass by reference” to a newbie. (Not you, of course.)
Value types
A piece of paper, on which is written the number 5. You use this number to calculate something.
Reference types
A piece of paper, on which is written a memory […]

21 April 2010 | C# | 1 Comment

When all you have is a hammer

… everything looks like a nail. The point I would like to make here is this: when all you know is C#, everything looks like a class.
(Note: When I say C#, I mean Java or C#. At the core both are the same. I only mean to avoid from having to repeatedly say “Java/C#” which […]

15 April 2010 | Uncategorized | No Comments

Calling a SOAP web service from PHP

The SOAP binding is RPC/encoded, and the WSDL is not published.
Using the PHP SoapClient:

define(’NEWLINE’, “<br />\n”);

// SOAP client

$options = array
(
‘location’ => ‘https://example.com:1234/sample/service’,
‘uri’ => ‘http://example.com/sample/namespace/data’,
’style’ => SOAP_RPC,
‘use’ => SOAP_ENCODED,
‘trace’ => true // in conjunction with $soapClient->__getLastRequest() below
);
$soapClient = new SoapClient(null, $options);

// SOAP header

$nsHeader = ‘http://example.com/sample/namespace/security’;
$elementName = ‘Security’;

$usernameToken->Username = new SoapVar(’user9′, XSD_STRING, null, null, null, $nsHeader);
$usernameToken->Password = […]

14 April 2010 | PHP | No Comments

Calling a WCF service from PHP

The WCF service needs to use basicHttpBinding.
The PHP code:

define(’NEWLINE’, “<br />\n”);

// SOAP client

$wsdl = ‘http://example.com/SampleWcfService.SampleService.Service?wsdl’;
$soapClient = new SoapClient($wsdl, array(’cache_wsdl’ => 0));

// SOAP call

$sampleData->SampleProperty = “abc”;

$parameters->sampleId = 123;
$parameters->sampleData = $sampleData;

try
{
$result = $soapClient->GetData($parameters);
}
catch (SoapFault $fault)
{
echo “Fault code: {$fault->faultcode}” . NEWLINE;
echo “Fault string: {$fault->faultstring}” . NEWLINE;
if ($soapClient != null)
{
$soapClient = null;
}
exit();
}
$soapClient = null;

//echo “<pre>\n”;
//print_r($result);
//echo “</pre>\n”;

echo “Return value: {$result->GetDataResult}” […]

8 April 2010 | .NET, PHP | 1 Comment

idea rumah