Summary of calling WCF in PHP and summary of calling wcf

Source: Internet
Author: User

Summary of calling WCF in PHP and summary of calling wcf

In the third week of the new job, I spent more than three years on. Net. Suddenly, I made a sharp turn in PHP, drifting over the bend, and the speed was 180.

Due to data integration, you have to use PHP to call WCF in the project.

There is little or no relevant information on the Internet. I posted a post in phpChina and no one has returned. It seems that the blog garden is always home.

Thanks to dudu's tireless reply and help, Thanks

============ The following is the body of text ==================

Using PHP to call WCF is very simple. All the processes require only two words, carefully

I. preparations:

1. soap. dll

Check whether ext in the PHP installation package has php_soap.dll [automatically integrated PHP, which usually exists. If it does not exist, you can download it online]

2. Modify the php. ini file

After confirming the first step, continue to find the PHP configuration file. Because each person's environment is different, for example, some use the integrated development environment, one-click Installation

Some users install them on their own. The location of php. ini may be different. In this case, use phpinfo () for viewing.

Find the file, open the file,

Found

; Extension = php_soap.dll

In this line, remove the semicolon.

If this row is not found, do not worry. You can manually add this row.

3. Restart apach.

Ii. call WCF

After the above steps are completed, our preparation is complete. The next step is to write the code.

Assume that all of us will use WCF and all have the foundation of PHP.

1. Release a WCF for calling

The following are two methods of WCF:

Public string SayHello ()
{
Return "Hello World ";
}

Public string GetData (string value)
{
Return "You entered is:" + value;
}

2. PHP terminal call

$ WcfURL = 'HTTP: // 192.168.3.102/Service1.svc? Wsdl '; // [This is the address of WCF]
$ WcfClient = new SoapClient ($ wcfURL );

$ Result1 = $ wcfClient-> SayHello ();
Print_r ($ result1 );

Echo '<br> ';
Echo $ result1-> SayHelloResult; // here the SayHello + Result is written together. I don't know the specific cause.

The above PHP code should be output normally as follows:

StdClass Object ([SayHelloResult] => Hello World)

Hello World

The first method is called successfully.

We continue to call methods with Parameters

In this case, you must use the WCF test client to test the WCF

I can see that the parameter of the WCF method at the beginning is GetData (string value), and t is displayed here, because it was written by a colleague in WCF for me and he is lazy, getData (string t) written directly at the time of definition ). For this laziness, I paid heavy code for 10 minutes!

Details connection: http://q.cnblogs.com/q/71331/

The modified PHP code is as follows:

$args = array('t' => '312');$wcfClient->GetData($args);
echo $result->GetDataResult;
echo '<br>';
print_r ( $result );

The above normal output should be

You entered is: 312
StdClass Object ([GetDataResult] => You entered is: 312)

 

The above completes PHP's call to WCF. Of course, some friends will ask more about it, such as the entire class or something as a parameter, returns a class or something ................ weak said, not playing so advanced ..

Thanks again dudu

The following is a reference article: http://blog.csdn.net/love__coder/article/details/6067611

Http://www.cnblogs.com/tianbang/archive/2012/05/07/2489149.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.