PHP SOAP server and .NET Client

On a previous post, it was the other way around a .NET SOAP server and a PHP client and this one is a PHP SOAP server talking to a .NET client. I am using a similar PHP SOAP Server output as before, but having to alter the return type to a complexType instead of a normal PHP SOAP server type.

The basic WSDL generation is very similar to the previous SOAP post, apart from parameter passed the Zend_Soap_AutoDiscover which is “Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex”, which creates the start of the newer return complexTypes.

if(isset($_GET['wsdl'])) {
    $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
    $autodiscover->setClass('QuoteOfTheDay');
    $autodiscover->handle();

here is the new return type for the function to return, it is a class that has public variable that is a string (you define as “” which sets up a string in PHP)

// the return class type
class theQuote {
// have a return value of type string
/** @var string */
  public $getTheQuote="";
}

and then just alter the phpDoc notation for the auto discovery with the Zend SOAP to create a return of theQuote class as above and alter the return variable to the class., below I have included the new WSDL output generated.

  /* phpdoc notation to return a complex type (a class) */
  /**
  * @return theQuote
  */
 function getQuote($quote) {
    $theQuoteR = new theQuote();
    /* just encase the string is in uppercase*/
    $symbol = strtolower($quote);
    /* if there is a quote for the day requested */
    if (isset($this->quotes[$quote])) {
      $theQuoteR->getTheQuote=$this->quotes[$quote];
      return $theQuoteR;
    } else {
      /* else error with default response*/
      $theQuoteR->getTheQuote=$this->quotes["monday"];
      return $theQuoteR;
    }
  }

here is the full source code for the PHP SOAP server

<?php
/* setup the including path for the zend library framework */
ini_set('include_path', '/usr/share/php/libzend-framework-php/');
 
//****************************************************
// Zend Framework 1.8
include_once 'Zend/Loader/Autoloader.php';
require_once "Zend/Soap/Server.php";
require_once "Zend/Soap/AutoDiscover.php";
$loader = Zend_Loader_Autoloader::getInstance();
$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);
//****************************************************
 
if(isset($_GET['wsdl'])) {
    $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
    $autodiscover->setClass('QuoteOfTheDay');
    $autodiscover->handle();
} else {
    $soap = new Zend_Soap_Server("http://localhost/projects/webservice/zend_soap_server_net.php?wsdl"); // this current file here
    $soap->setClass('QuoteOfTheDay');
    $soap->handle();
}
 
// the return class type
class theQuote {
// have a return value of type string
/** @var string */
  public $getTheQuote="";
}
 
class QuoteOfTheDay {
 
  /* the quotes to be used from within the function getQuote */
  private $quotes = array("monday" => "Monday's child is fair of face", "tuesday"=>"Tuesday's child is full of grace","wednesday" =>"Wednesday's child is full of woe",
  "thursday" =>"Thursday's child has far to go", "friday" => "Friday's child is loving and giving", "saturday" =>"Saturday's child works hard for a living",
  "sunday" =>"But the child who is born on the Sabbath Day - Is bonny and blithe and good and gay");  
 
  /* phpdoc notation to return a complex type (a class) */
  /**
  * @return theQuote
  */
 function getQuote($quote) {
    $theQuoteR = new theQuote();
    /* just encase the string is in uppercase*/
    $symbol = strtolower($quote);
    /* if there is a quote for the day requested */
    if (isset($this->quotes[$quote])) {
      $theQuoteR->getTheQuote=$this->quotes[$quote];
      return $theQuoteR;
    } else {
      /* else error with default response*/
      $theQuoteR->getTheQuote=$this->quotes["monday"];
      return $theQuoteR;
    }
  }
}
 
?>

Here is the newer WSDL output (snipped) from the new PHP SOAP server that creates a complexType return type for the .NET environment to be able to use.

<types>
-
<xsd:schema targetNamespace="http://localhost/projects/webservice/zend_soap_server_net.php">
-
<xsd:complexType name="theQuote">
-
<xsd:all>
<xsd:element name="getTheQuote" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
-
<portType name="QuoteOfTheDayPort">
-
<operation name="getQuote">
<documentation>@return theQuote</documentation>
<input message="tns:getQuoteIn"/>
<output message="tns:getQuoteOut"/>
</operation>
</portType>

Here is the .NET client

Since we have a new WSDL generation, will need to generate a newer DLL that will allow the .NET to use the class structure. Please note I am using mono as my .NET environment, so if you are using .NET in Windows then you could either include the WSDL within the Visual Studio or use very similar commands as below.

wsdl2 http://localhost/projects/webservice/zend_soap_server_net.php?wsdl
gmcs QuoteOfTheDayService.cs /t:library /r:System.Web.Services

which will generate the QuoteOfTheDayService.dll and with the code below

using System;
 
namespace codingfriendssoap
{
    class Test_Php_Soap
    {
 
static public void Main()
{
  QuoteOfTheDayService quoteService = new QuoteOfTheDayService();
 
  Console.WriteLine("mondays quote " + quoteService.getQuote("monday").getTheQuote);
}
    }
}

to compile that you once again I am using mono so these are the commands that I am using, but with .NET framework in Windows the commands may be different to compile the program e.g. (mcc)

gmcs web_service_client_php.cs /r:QuoteOfTheDayService.dll

the /r includes the dll generated of the above generated PHP SOAP server this is the output

mondays quote Monday's child is fair of face

here is the XML response from the PHP SOAP server, which includes getTheQuote return wrapped around the theQuote class.

<SOAP-ENV:Body><ns1:getQuoteResponse><return xsi:type="ns1:theQuote"><getTheQuote xsi:type="xsd:string">Monday's child is fair of face</getTheQuote></return></ns1:getQuoteResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

4GB – 32bit northbridge BAR1 error

With the Laptop that I have, it appears to have a 32 bit northbridge with a 64 bit cpu’s, I have logged this error with the PCI kernel group because hopefully they will be able to give some advice and also I am giving data back to the Linux group on the whole.

Shall put any advice on the kernel PCI group list back on this page regarding the error, if anyone wants to look over the 2GB/4GB dmesg + /proc/iomem files just say.

“I have a acer aspire 9815 with from what I have read a 32bit Northbridge and when you add 4GB of RAM with a nVidia 256 of “virtual
ram” causes a base address registers (BAR1), but works fine with 2GB because there is a problem with the way that Linux kernel is
allocating the memory associated with the devices and places then out of range.

Here is my lspci for the PCI host bridge

Host bridge: Intel Corporation Mobile 945GM/PM/GMS, 943/940GML and
945GT Express Memory Controller Hub (rev 03)
PCI bridge: Intel Corporation Mobile 945GM/PM/GMS, 943/940GML and
945GT Express PCI Express Root Port (rev 03)

From this website it appears that some one was trying to update the PCI IOMEM part of the kernl

http://tjworld.net/wiki/Linux/PCIDynamicResourceAllocationManagement

but says that it will be in the .30 / .31 kernel but I am not able to still use the 4GB of ram and I am using the 2.6.31-10-generic
#35-Ubuntu SMP Tue Sep 22 17:33:42 UTC 2009 i686 GNU/Linux from a kubuntu 9.10 setup and was hoping to have the fix already applied.

Was wondering since I am using the k/ubuntu kernel does the “real” kernel have the PCI IOMEM Upgrade ? or do I have pass some kernel
parameters on grub to allow for this to work correctly ? or has there been another upgrade to the PCI structure that will come in a later
release ?

Also there was some advice to update the BIOS for some laptops and set the upper memory limit, does this make the PC memory have a virtual
head to it and thus the OS will not see the rest of RAM ? or is it just for the PCI setup aspects that look at the upper memory limit and
the rest of the OS can see the and use the rest of the RAM ?

Any advice would be great.”

UPDATE

The only advice was that how about trying out the 64bit kernel, which is what I am using.

Constant casting

Constant casting is when you are for example calling a external library function that does not understand the const (constant) type and so you will need to take it off because the program will do something funny otherwise, crash. etc..

Here is a example code of a const_cast

#include <iostream>
 
using namespace std;
 
int exampleextenalfuction(int value)
{
	// you can alter the value if you want to, since it is not longer a constant value
	return value  + value;
}
 
int main()
{
	const int constvalue = 2;
 
	cout << constvalue << endl;
 
	cout << "Calling a external function that does not use constant types" << endl;
 
	cout << exampleextenalfuction(const_cast<int&>(constvalue)) << endl;
}

Static casting

Static casting is when you want to convert one type into another, static casting is used allot of the time without even knowing. For example

int value = 2;
float t = float(value);

the float(value) is a static casting of converting one value into another. Below is a full code example

#include <iostream>
 
using namespace std;
int main()
{
	int i = 3;
	// the float(<value)> is basically a static cast from a interger value into a float
	cout << float(i) << endl;
	cout << static_cast<float>(i) << endl;
}

It is very small since static_cast’ing is very basic in nature, but the only problem is that you have to check to make sure that there is a error e.g not NULL.

Execution order

Execution order of programs code is very much a vital thing to understand and where some fault finds will take a long while to figure out. Basically like in maths where there is a order of calculating, well in coding structures and also multitasking and multi-threading setups the execution order may be incorrect for lines of code.

Here is some examples, the first is when will a function be called and the later when post/pre incrementation will take place.

#include <iostream>
 
using namespace std;
 
int value =1;
 
int setvalue2()
{
	cout << "setting value"<<endl;
	value = 2;
	return value;
}
 
int returnvalue()
{
	cout << "renting value"<< endl;
	return value;	
}
 
int main()
{
	// depending on the order of execution the value may be
	/* setvalue2 called first
		(setvalue2 = 2 / returnvalue = 2) = 1
	   returnvalue called first
		(setvalue2 = 2 / returnvalue = 1) = 2
	*/
	cout << setvalue2() / returnvalue() << endl;
 
	int i;
	i = i++ - ++i;	// not sure what i will be because the pre/post increaments 
	i = 3, i++, i++; // i will equal 5 because in correct order.
}

Dynamic Casting

Dynamic casting, means that you can convert one object into another that is off the same type. For example, if you had a base class called Shape and a inherited class called Rectangle then you are able to convert a Shape object into a Rectangle.

Rectangle *rec = dynamic_cast<Shape *>(shapeobject);

sort of thing, there has to be a virtual function within the base class otherwise the compiler will complain, but apart from that that is about it.

Dynamic casting allows for NULL returns which is the best thing, because you can test to see if the casting actually worked and not to do anything silly on a NULL object which would crash the program.

Pointer casting uses the sytnax

<type> *p_subclass = dynamic_cast<<type> *>( p_obj );

Reference will not throw an error/expcetion so will need to check std::bad_cast< typeinfo header >, here is the syntax

<type> subclass = dynamic_cast<<type> &>( ref_obj );

Hopefully this will make more sense for how and why it works.

#include <iostream>
 
using namespace std;
 
class classA 
{
	public	:
		int x;		// should be private
		char y;		// should be private
 
		classA();
 
 		virtual ~classA() {}; 	// need to have a virtual function for dynamic casting
};
 
// basic classA constructor
classA::classA()
{ 
	cout << "classA" << endl; 
	x = 1; 
	y = 'a';
}
 
 
class classB : public classA
{	
	public :
		int b;		// should be private
 
		classB();
 
		~classB() {};	// complete the virtual
};
 
// basic classB constructor
classB::classB()
{
	cout << "classB" << endl;
	x = 2;
	y = 'b';
}
 
int main()
{
	classA newa;	// classA obj
	cout << "class A constructed" << endl;
	classB newb;	// classB obj
	cout << "class B constructed" << endl;
 
	cout << "NewA X " << newa.x << endl;
	cout << "NewB X " << newb.x << endl;
 
	// point a classB to a already created classB object
	classB *normalB = &newb;
	// dynamic_cast a normalB object (newb) to another classA object
	classA *dynA = dynamic_cast<classB *>(normalB);	
	cout << "dynamic A X " << dynA->x << endl;
 
	// does not work, because you cannot convert classA into a classB, but if classA was pointing to a classB type.
	classA *normalA = &newa;
	classB *dynB = dynamic_cast<classB *>(normalA);
	if (dynB)	// above produces a 0 because invalid.
	{
		cout << "dynamic B X " << dynB->x << endl;
		cout << "dynamic B X " << dynB->b << endl;
	}
 
	// this does work because it is converting from a pointer of classB type, which was "sitting" in a classA container
	// and then is converted back to a classB
	classA *normalA2 = &newb;
	classB *dynB2 = dynamic_cast<classB *>(normalA2);
	if (dynB2)	// above produces a 0 because invalid.
	{
		cout << "dynamic A2X " << normalA2->x << endl;	// output is 2 because it was a classB constructed
		cout << "dynamic B X " << dynB2->x << endl;
		cout << "dynamic B X " << dynB2->b << endl;
	}
 
}

C++ DLL Objects accessed from C#

Because there is a few things that c# cannot do compared to c++, e.g. cpu/memory management. And also there is probably allot of dll’s out there are still required for some events, c# is able to communicate with these files and use there functions within the c# language.

To create an dll within Visual Studio 2005 within the language c++, if you do the following

1. New project -> c++ -> empty project
2. Enter project name (e.g. hellocdll)
3. Right click source files ( in the solution explorer) add-> new item
enter an cpp filename.
4, Right click on the main project heading in the solution explorer -> properties
configuration properties->general inner screen project defaults -> configuration type, alter to dynamic library (.dll)
5. Copy and paste code and then compile.

#include <stdio.h>
 
extern "C"
{
  __declspec(dllexport) void DisplayMessageFromDLL()
  {
              printf ("Hi From the C DLL!\n");
  }
 
  __declspec(dllexport) int DisplayValueAndReturn(int i)
  {
         printf("Value %i\n", i);
         return i+2;
  }
}

The extern “C” means that the references within the code are going to be available externally and marco __declsepc(dllexport) is for the MS compile to inform that functions are to be available within an dll file.

To create an c# project to communicate with the above dll

1. New project -> c# -> empty project
2. Enter project name (e.g. hellodlltest)
3. Right click on the project name ( in the solution explorer) add-> new item
select class and enter a filename
4. Copy and paste the code and then compile. (you may need to change the Dllimport to the dll file name that has been created from the c dll project)

using System;
using System.Runtime.InteropServices;     // DLL support
 
namespace hellodlltest
{
    class hellodllC
    {
        [DllImport("hellocdll.dll")]
        public static extern void DisplayMessageFromDLL();
 
        [DllImport("hellocdll.dll")]
        public static extern int DisplayValueAndReturn(int i);
 
        static void Main ()
           {
                  Console.WriteLine ("C# program 'talking' to an C DLL");
            DisplayMessageFromDLL();
            Console.WriteLine(DisplayValueAndReturn(3).ToString());
           Console.ReadLine()
           }
    }
}

5. Copy the dll file from the debug directory of the c++ created dll project and place into the created bin/debug directory for this c# project