This article for you to share is the PHP implementation WebService (measured C # and Java can be called), a friend can refer to
Using PHP to build a webservice that is available in other languages such as C # and Java is different from what most of the web-based webservice feel like with PHP. For the complex input parameters and output parameters of the interface, it is recommended to unify the input parameters and output parameters directly into XML string or JSON string. Here is how to implement a webservice, and for the input and output parameters of the format, how to manipulate the XML string is not much introduction, a search a lot of, but pay attention to the XML and JSON to pay attention to the parameters of filtering and checking. This article introduces the WEBSERVICE,NO-WSDL with WSDL file, the way is relatively simple, here do not introduce
Check and open the SOAP extension
You first need to turn on the SOAP extension, remove the semicolon before extension=php_soap.dll in the php.ini file, and then restart Apache. See if Phpinfo opens soap. Specifically how to do this skip, implementing WebService is required for SOAP extensions.
Build C # WebService in VS
The web found on the PHP production WSDL mode of the generated WSDL file to build the WebService only PHP can use, simply do not pit. So this is the way to generate a WSDL file in the form of a curve saving. A webservice is built in C # to generate the WSDL, which can then be used as soon as a slight change is made.
1. Create a project->asp.net a Web application;
2.b. Right-click Add-New Item Selection Web service (ASMX), Solution,
3. Write the interface and note that the function to be published in C # should be added [WebMethod], which may also create some new classes:
4. Write completed press Ctrl+f5 The following appears, followed by a URL followed by the? WSDL will appear as shown in the WSDL, save as can be.
5. Change the location of the <soap:address> in the generated WSDL file to the published address of PHP WebService:
6.PHP Writing WebService Interface:
7. Release WebService:
<?php/** * Created by Phpstorm. * User:damon * DATE:2018/1/26 * time:11:16 *///introduced automatic loading require __dir__. '/vendor/autoload.php '; $wsdlfile = ' meswebservice.wsdl ';//wsdl file path $webserver = new \soapserver ($wsdlfile); $ Webserver->setclass (\src\meswebservice::class); $webserver->handle ();
Note that the method of the Web service is declared at most one parameter, but when the method is called it must pass value1,value2 two arguments. (This is very confusing, I understand that when the method is called, the system puts all the parameters in an object to pass over). The return value is also very special, not to return $arry directly, but to put it in an object and return it. The key value in the return value corresponds to the name in the WSDL.
To invoke tests using C #
1. New Project->asp.net Web application build a project, as before;
2. Right click on the project below the reference, add a service reference, click on the Advanced Jump Service reference settings, click on the bottom right corner of the Add Web reference, appear as shown:
3. Fill in the URL with the address of the published WebService service, if it appears correctly after carriage return, then click Add Reference after changing the Web reference name as required:
4. Then right-click Project, add New item, select Web Form, and edit the contents of the. aspx.cs file.
5.E. Finally press Ctrl+f5 run to see the corresponding output, as shown in, the PHP implementation of WebService in C # can be called correctly.