Using WCF Services with PHP

WBOY
发布: 2016-06-23 14:34:24
原创
1068 人浏览过

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.

I conducted my first experiment with PHP. PHP is widely used in the world of the Web and in all likelihood there will dawn a day when DT is asked just for such an integration. As PHP4 development and support is soon going to be discontinued, I didn't bother with an example using PHP4 SOAP tools. PHP5 is on the market and it comes with a quick and stable SOAP library. The performance is many times better than in case of similar widgets written for PHP4.

I have Apache and PHP5 running on Windows and for SOAP support I have to use an extension named php_soap.dll. Thus, I have to remove the comment mark in front of the appropriate php.ini line and restart Apache.

As an example I will present a PHP code calling the service's Add() method and writing the result on the screen. An example of WCF code can be found in our blog, in the posting WCF Services ? Let's Get Started.

<?phpheader('Content-Type: text/plain');echo "WCF Test\r\n\r\n";$client = new SoapClient('http://gamma/wcftest/MathService.svc?wsdl');$obj->x = 2.5;$obj->y = 3.5;$retval = $client->Add($obj);echo "2.5 + 3.5 = " . $retval->AddResult;?>
登录后复制

If nothing went wrong, the result should be something like this:

    WCF Test    2.5 + 3.5 = 6
登录后复制

As you can see, using WCF services in PHP is very simple. The SOAP library provided along with PHP5 does a great deal of the work "behind the curtains", leaving us with an easily readable brief code.

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板