Page 1 of 1

how to send an object to C# WCF service from PHP using SOAP

Posted: Thu Jul 22, 2010 1:33 am
by toretotech
Hey all!

I'm having trouble sending a custom object thats defined as a datacontract in my WCF web service from PHP. I'm attempting to accomplish this via SOAP.

The object is called simplyCustomer and pretty much just has a bunch of attributes like name, phone number address, etc. Very generic stuff.

I am able to receive this object in PHP without any problems. It comes in as a stdClass and is very workable. However, when I create the exact same stdClass and attempt to send it back to the WCF service, the SOAP request is somehow set to NULL.

Here is the stdClass:

Code: Select all

$taxInfoObj = new stdClass;
        $taxEntry = new stdClass;
        $newCustomer = new stdClass;
        
        $newCustomer->name = "ci_testName";
        $newCustomer->contact = "ci_testContact";
        $newCustomer->street1 = "ci_testStreet";
        $newCustomer->city = "ci_testCity";
        $newCustomer->province = "ci_testProvince";
        $newCustomer->postalCode = "ci_testPostal";
        $newCustomer->country = "ci_testCountry";
        $newCustomer->phone1 = "5149876543";
        $newCustomer->fax = "5149876542";
        $newCustomer->email = "ci_testEmail@company.com";
        $newCustomer->website = "www.ci_testWebsite.com";
        $newCustomer->languagePref = "ci_testLang";
        $newCustomer->shippingContact = "ci_testShipContact";
        $newCustomer->shippingStreet1 = "ci_testShipStreet";
        $newCustomer->shippingAddressName = "ci_testShipName";
        $newCustomer->shippingCity = "ci_testShipCity";
        $newCustomer->shippingProvince = "ci_testShipProv";
        $newCustomer->shippingCountry = "ci_testShipCountry";
        $newCustomer->shippingPostalCode = "ci_testShipPostal";
        $newCustomer->shippingPhone1 = "5149876543";
        $newCustomer->shippingFax = "5149876542";
        $newCustomer->shippingEmail = "ci_testShipEmail@company.com";
        $newCustomer->isDefaultShippingAddress = 1;
        $newCustomer->taxInfo = array(
            $taxInfoObj->ArrayOfstring = array(
                $taxEntry->string = array("0",""),
                $taxEntry->string = array("0",""),
                $taxEntry->string = array("0",""),
                $taxEntry->string = array("0",""),
                $taxEntry->string = array("0",""),
                $taxEntry->string = array("0",""),
                $taxEntry->string = array("0","")
                )
            );
Here is the function call that I use:

Code: Select all

           //Connecting to Bridge Service
            $simplyService = new SoapClient('http://192.168.2.36/bridgeService/simply.svc?wsdl',array('trace'=>1));
            
            //build parameter
            $params = array('simplyCust'=>$customerObject);
            
            //Send request to Bridge Service
            $retVal = $simplyService->__soapCall("addCustomer",array('parameters'=>$params));
            $lastRequest = $simplyService->__getLastRequest();


Here is the envelope that is generated:

Code: Select all

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:addCustomer/></SOAP-ENV:Body></SOAP-ENV:Envelope>
The parameters should be where addCustomer is but there's nothing there.

Any help would be greatly appreciated! Thanks!

Re: how to send an object to C# WCF service from PHP using S

Posted: Thu Jul 22, 2010 1:46 am
by John Cartwright
Where is $customerObject defined?

Re: how to send an object to C# WCF service from PHP using S

Posted: Thu Jul 22, 2010 11:02 am
by toretotech
that, my friend is a very good question. First off, I am doing all this using the CodeIgnter framwork.

The customerObject is created in a Controller which then passes the object to my library function – who then handles the connection to the WCF service.

Now that I think of it, could it be because I define the class in the controller by the time it gets to the library function, it has no idea what it is?