>  기사  >  백엔드 개발  >  Using WCF Services with PHP

Using WCF Services with PHP

WBOY
WBOY원래의
2016-06-23 14:34:241060검색

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.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:php 连接 sqlserver다음 기사:Sorting Array Values in PHP