First, the preparatory work
1, installation wampserver: Process slightly
2, Configuration wampserver:
2.1 Open the php.ini file, remove it, extension=php_soap.dll the semicolon here.
There are also said to take this; Extension=php_openssl.dll in front of the semicolon also removed.
2.2 For example, the Php_soap is played √.
2.3 For example, open the httpd.conf file, locate listen 80, and change the 80 port to a larger port, such as 8000. Because the 80 port can also be used in other programs.
There are PHP pages in this directory. index.php is the default page. Entering http://localhost:8000/in the browser will enter the default homepage
Ii. Building a WCF service
You can right-add---New Item---a WCF service directly in the Web project, generating the following two files.
Test in these two files. The above operation saves the configuration and starts the service. The service is up only when the Web project is running.
Note: The parameter names of the corresponding methods in the interface and implementation classes should be consistent.
as follows, the parameter ID name should be the same. Article is an article class
in IService1.cs Medium:
[OperationContract]
Article GetArticle (string id);
in Service1.svc Medium:
Public article GetArticle (string id)
{
Do something
}
Third, PHP calls a method in WCF
PHP can call the C # method format (tested):
The following is the C # method format
public string Fun ();
public string Fun (string str); This only passes string and int types, and the number of arguments can be multiple.
Public article GetArticle (string id);
Publis string[] Getstrs ();
Public list<article> getarticlelist (string flag);
public void addarticle (article art);
Again, the parameter name should be the same as the argument name in the corresponding interface.
--------------------------------------------------------------------------------------------------------------- -----
PHP Calls:
"public void addarticle (article art)"
Description: The following service address, you can right-click on the service1.svc file-browser view
<?php
$client = new SoapClient (' http://localhost:8000/WCF/Service1.svc?wsdl ');
$result = $client->addarticle (
Array (
' Art ' = Array (
' Title ' = ' new PHP article title '
)
));
?>
Note that art is an instance of the article class, and title is an attribute in the article class.
"public string Fun (string str);"
<?php
$client = new SoapClient (' http://localhost:8000/WCF/Service1.svc?wsdl ');
$obj->str= "3";
$result = Fun ($obj) $client
echo $ result--funresult;
?>
Note Art, title is an attribute in the article class.
"Public article GetArticle (string id);"
<?php
$client = new SoapClient (' http://localhost:8000/WCF/Service1.svc?wsdl ');
$obj->id= "3";
$result = $client->getarticle ($obj);
Echo var_export ($result->getarticleresult->title);
echo "<br/>";
Echo var_export ($result->getarticleresult->author);
?>
Note: Title and author are the two properties of the article class.
"Public list<article> getarticlelist (string flag);"
$client = new SoapClient (' http://localhost:8000/WCF/Service1.svc?wsdl ');
$obj, flag = "3";
$result = $client-Getarticlelist ($obj);
Echo Var_export ($result-getarticlelistresult-> article);
Echo var_export ( article [0]-> TITLE , Getarticlelistresult, $result);
"Publis string[] getstrs ();"
$client = new SoapClient (' http://localhost:8000/WCF/Service1.svc?wsdl ');
$result = $client->getstrs ();
$AA = $result->getstrsresult; Output entire array
$AA = $result->getstrsresult->string[0]; The No. 0 item in the output array
Print_r ($AA);
PHP calls the methods provided by WCF