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

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.

Here is what the dataContract looks like:

    public class simplyCustomer
        public int id;
        public string name;
        public string contact;
        public string street1;
        public string street2;
        public string city;

So I have a function that takes simplyCustomer as parameter on WCF service. The php can receive simplyCustomer just fine using another function that returns one. However, if I call the one that accepts it using this code in PHP:

$retVal = $simplyService->__soapCall("addCustomer",array('parameters'=>$params));

The SOAP envelope that this call generates leaves the object NULL causing the WCF service to complain about null reference.

Here is the envelope that is generated:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:ns1=""><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!



I faced the same issue when building a private project.

My solution was to use T4 to generate service- and datacontract proxies, maybe you find it useful. Message me if you have any questions, the templates are not tested to their full extent.

You find the templates on github, including sample servicecontracts/datacontracts:

feel free to fork the project!


Though this is asked while before, thought to add my input since I came accros the same issue.

Assuming your operation contract look something similar to

public <return_type> addCustomer(simplyCustomer parameters);

what you have suggested should work given that $params got all the required values set on initialisation where ever that has done and variable names are exactly similar to data contract.

Few tips going through this though.

1) If you have manage to send the object to the service, Could check the service logs to see what has gone wrong.

2) Just check your constructor to see all the parameters are set.

3) Also good to check that soap client is initialized and consumed properly.

eg : (following is, one of many possibilities)

$client = new Client( $baseUrl, array('soap_version' => SOAP_1_1,));
$result = $client->addCustomer(array("parameters" => $params ));

I had the same kind of problem. Cant see how you built your $params but I solved mine by doing this:

$username = "test";
$password = "test";

$input = array ("composite" => array("Password" => $password, "UserName" => $username));


My service method looks like this

AuthenticationData AuthenticateUser(AuthenticationData composite);

Using Fiddler is a good help when figuring out how to build your Soap stuff

Need Your Help

Django Celery socket.error: [Errno 111] Connection refused

linux django ubuntu celery django-celery

When running the command celery status on my production server I get this error:

Why does @Table not work for me?


Can anybody tell why is this query not working?