Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.






Using WCF Services with PHP

I recently wrote two postings on the subject of WCF services: WCF Services – Let's Get Started and WCF and Unit Tests. One could see that creating and testing services was not complicated at all. Let's go on and take some steps nearer to the real world – our service is used by SOAP clients running on different platforms.


NB! This blog is moved to

Click here to go to article


Gabest said:

Packing arguments into undeclared objects... well, isn't there a better way? If php runs on Windows then I found it much more convenient to generate a proxy class library dll and use that through COM, but that's not always the case, currently I have to make a call from linux and that's how I found your article googling for a solution.

# October 2, 2007 4:56 AM

DigiMortal said:

Thanks you for your reply. I have to admin that undeclared object is not a best solution. It is really better to create a class for arguments object.

# October 6, 2007 10:36 AM

DigiMortal said:

Which version of PHP you are using? If it is PHP5, do you use built-in SOAP support? If you can provide me this information it is easier for me to help you.

# April 8, 2008 8:21 AM

Lincy said:

PHP 5, N yes the built in SOAP support

# April 8, 2008 10:42 AM

Wade said:

Getting this error when calling method "Fatal error: Uncaught SoapFault exception: [HTTP] Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'."

PHP Version => 5.2.3-1 (failed on both cli and apache)

PHP Box => ubuntu 6.3

ISS Box => Vista 64 ult

Using Soap which is compiled in.

Any ideas?

# May 8, 2008 4:06 AM

DigiMortal said:

I think you have problem with SOAP version. Check out what SOAP version uses WCF and which one is used by PHP. Then make sure that they both will use same version.

# May 8, 2008 4:43 AM

Wade said:

Ok problem solved. Changed binding to basicHttp and it worked with PHP.

My new problem now is using multiple endpoints. I'd like to have a wsHttp and basicHttp. Trying to workout how now.

# May 8, 2008 9:36 PM

Wade said:

Yeah that's what I used. The array declaration was gobbled by the url parsing code.

# May 14, 2008 12:36 AM

DigiMortal said:

Make sure that WCF and PHP app will use same SOAP protocol version.

# May 21, 2008 5:45 PM

Banu said:

What is WCF? Sorry i am new to web services.



# May 21, 2008 7:42 PM

DigiMortal said:

WCF stands for Windows Communications Foundation. It is technology to build services and it was shipped with .Net Framework 3.0. Now you can build stand-alone services. Previously you were bind to ASP.NET and Web Service project that offered only SOAP. With WCF you can also use the other standard for web services.

# May 22, 2008 2:05 AM

Banu said:

But I dont use .net framework. I use windows XP Professional ver 5.1 and use XAMPP for windows version 1.6 and soap client and version are both enabled in my xampp and use php 5.2.5.


# May 22, 2008 9:46 AM

DigiMortal said:

I really don't understand what and how you are doing and how is this related to WCF :)

# May 22, 2008 9:54 AM

DigiMortal said:

Hmm.... svc extension points to WCF. Try to change SOAP version in your PHP request. Instead of

'soap_version' => SOAP_1_1

try out

'soap_version' => SOAP_1_2

# May 22, 2008 2:45 PM

Andrey said:

$client->soap_defencoding = 'UTF-8';

# July 22, 2008 10:59 PM

Yuval said:

I see there are some comment about WSHttpBinding but it is not clear how to use it.

Can you please explain what should I do in order to consume WCF service with WSHttpBinding from PHP

Is it possible to do it from a computer outside of the domain?


# September 4, 2008 1:47 AM

Kiemieuk said:

For the Banu problem,

i think it caused of banu put the service url in svc extension.

For .Net i think its okey buts for PHP,

it should put .svc/wsdl? after the .svc extension

Maybe its can solver the problem.

Buts thank to the blog owner, your blog really teaching me to doin well in my WCF

# March 24, 2009 2:31 AM

DigiMortal said:

Thanks for good words, Kiemieuk :)

# March 24, 2009 6:32 AM

ciary said:

hi all,

i'm pretty new to webservices but i need them for a project to convert a database.

but since this is new, i first tried to put a simple 'Hello World!' on my screen using WCF.

now when i tried this code (see below) i got a fatal error. i dont know how to solve it. i've put the folder with my svc into the home folder of my website.


my code:


header('Content-Type: text/plain');

echo "WCF Test\n";

$client = new SoapClient('webservice try 1/webservice try 1/Service1.svc?wsdl');

$retval = $client->Test();

echo $retval;



my output:

WCF Test

<br />

<b>Warning</b>:  SoapClient::SoapClient() [<a href='soapclient.soapclient'>soapclient.soapclient</a>]: I/O warning : failed to load external entity &quot;webservice try 1/webservice try 1/Service1.svc?wsdl&quot; in <b>C:\xampp\htdocs\page\testWCF.php</b> on line <b>6</b><br />

<br />

<b>Fatal error</b>:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'webservice try 1/webservice try 1/Service1.svc?wsdl' : failed to load external entity &quot;webservice try 1/webservice try 1/Service1.svc?wsdl&quot;

in C:\xampp\htdocs\page\testWCF.php:6

Stack trace:

#0 C:\xampp\htdocs\page\testWCF.php(6): SoapClient-&gt;SoapClient('webservice try ...')

#1 {main}

 thrown in <b>C:\xampp\htdocs\page\testWCF.php</b> on line <b>6</b><br />


any help would be welcome

# April 15, 2009 6:46 AM

ciary said:

ok, seems i copied my url wrong. although i encountered a second problem on line 8. 'Unsupported Media Type'

does anyone know how i should fix that??

ty :)



# April 15, 2009 8:01 AM

Mohammed said:


I really need your help please

i keep getting this error don,t know what to do with it

The SOAP action specified on the message, '', does not match the HTTP SOAP Action


# April 17, 2009 10:26 AM

Fernando Mendes said:

the PHP SoapClient class implements the WS-I standard.  To resolve the HTTP SOAP action mismatch exception:

Change the binding of the WCF service in the web.config file from binding="wsHttpBinding" to binding="basicHttpBinding".

Good luck...

# April 22, 2009 6:28 PM

Venture Digital said:

Thank you DigiMortal, it's a great post and helped me a lot.

# July 17, 2009 11:31 AM

Diego Toala said:

Thanks a lot!! Great Article , I was using NuSoap and was difficult consume the wcf service, I can't find actual info about NuSoap, You Rock!

# July 18, 2009 12:07 AM

Boo Radley said:

Does anyone know how to pass credentials from a PHP client to a WCF service if said service requires a username and password?

# October 6, 2009 10:08 AM

Sherry F said:

Riaan Bergh - how did you resolve the issue?  I'm having the same problem.  The service is not owned by me and I can't "Change the binding of the WCF service in the web.config file from binding="wsHttpBinding" to binding="basicHttpBinding"."  I have to somehow set in php/nusoap that we need to USE basicHttpBinding.  Is that a setting we can use in nusoap?  

# November 11, 2009 11:39 PM

noobs said:

Can i authenticate using a certificate and nuSoap,

I need to call a .NET Webservice using the given certificate.

Can anyone please help, i am new to Webservice and do apologize if my question sounds


# July 12, 2010 3:22 AM

lonwin said:

Thanks a lot!! Great Article! help me solved my problem!

# April 20, 2011 2:13 AM