Search EggHeadCafe's Job Board
EggHeadCafe Silverlight WPF ASP.NET VB.NET C# Excel SQL Server SharePoint
search
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

WebArticlesForumsFAQs
JavaScript
ASP
ASP.NET
WCF

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

Operating SysArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Lounge
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

Accessing IIS Hosted WCF Services from PHP


By Aaron Katz
Printer Friendly Version
View My Articles
78 Views
    

Using PHP to access IIS hosted WCF services. Discussion and example.


                                      Accessing IIS Hosted WCF services from PHP

There have been many articles, published recently, on building and configuring IIS hosted “WCF services”. The number of performance and security enhancements in WCF services makes them very attractive for development community.  One of the main features of WCF is that they are meant to be “consumed” from any client (“Cross-platform Data Exchange”).  in our opinion, however,  there is an informational “white spot” on that very subject. The majority of available publications on the web discussing WCF service consumption use the “.Net platform”.   This is fine for developers whose business requirements allow them to stay strictly within the .Net environment. 

A recent client of ours had the need to access our web service using PHP.  They were given “.wsdl file” containing all the necessary information.  However, a day later, we were notified by the client that they could not access our service using their technology – PHP.  We therefore decided to try to connect to the WCF service using the client’s technology – PHP. This was somewhat of a challenge for us as we are not PHP experts -- as we specialize in Microsoft technologies.   

We invested some time researching basic PHP features on http://www.php.net and after some trial and error, built a properly working PHP file. 

As we’ve done in recent articles, we share the results of our work with the “EggheadCafe.com community” in the hope that it will save some time and pain to other developers with similar needs.  In particular, we find that simple examples often clearly illustrate a technique often better than in textbooks – where one often finds it difficult to discern the essence of a technique.

Therefore, here is a simple working solution to access IIS hosted WCF service returning an object.

 $client = new SoapClient("your.wsdl");  //create a “SoapClient” using a given .wsdl file

 //declare an object which will be passed to WCF service:
class myClient
{
 public $FirstName = '';  
 public $LastName = '';  
 public $PhoneNu = '';
}

//instantiate the object created
$mc = new myClient();

//if you need to provide any information for your WCF service, this is the right place to do it

$mc->PhoneNu = “555-3456”;

//now, we need to wrap our object in the parameter we will pass
$myParam = array(‘parameterName’=>$mc);


/*Pay attention to ‘parameterName’.  This should match to your parameter name in the
   WCF service method parameter name, or the call will fail.
   Example of WCF service method:
 
public CompositeType GetDataUsingDataContract(CompositeType parameterName)
*/

//The next step is to call our method with the assigned parameter
$wcf = $client->GetDataUsingDataContract($myParam);

//Get the result from the method call
$wcfResult = $wcf->GetDataUsingDataContractResult; //Note that PHP using method name with ‘Result’

//And now, we are ready to access our service object populated by WCF:
echo $wsResult->LastName;

 

That’s all there is to it. It will be interesting to see to see people with PHP skills participating in this discussion.

Happy programming, everyone!

Aaron J. Katz
Yuri Kasan

 

 


Biography - Aaron Katz

Aaron J. Katz -- Director of New Technolgy for FOJP Service Corporation in New York. Aaron has over 25 years experience as a developer using a variety of technologies. Significant experience in guiding corporations in the appropriate use of technology to achieve business goals. Certified PMP (Project Management Professional).


button
Article Discussion: Accessing IIS Hosted WCF Services from PHP
Aaron Katz posted at Wednesday, December 03, 2008 8:48 PM
Original Article
 

question
Raj Cool... replied to Aaron Katz at Wednesday, December 03, 2008 10:29 PM

It is very difficult for me to understand your article related to WCF. :-) Could you tell me what is WCF services and why we used it?

Thnaks,

Megha

 

Response to "Could you tell me what is WCF services and why we used it?"
Aaron Katz replied to Raj Cool... at Saturday, December 13, 2008 11:47 PM

Please see this extensive article on MSDN:

http://msdn.microsoft.com/en-us/library/bb332338.aspx

Enjoy!

AJK

 

good post
Rexon Jeyasingh replied to Aaron Katz at Wednesday, July 08, 2009 3:06 PM
end of post