WebService-php- 1 (16), webservice-php-16
I have read a lot of information about webservice in php recently, thank you Yan Shiba for sharing, it helped My process of building the server. Record your study notes as follows, including Yan Shiba’s notes.
WebService
1 Quickly understand WebService
In layman's terms: call the method of the remote server according to a certain XML format, and the server returns XML content in a certain format.
"Certain format"----SOAP (Simple Object Access Protocol) simple object The access protocol is a simple protocol for exchanging information in a decentralized or distributed environment. It is an XML-based protocol
.
Remote server ---- generally delivers messages through the HTTP protocol
Summary: WebServie == XML in HTTP protocol Soap format
Example 1: soap request
POST /WebServices/MobileCodeWS.asmx HTTP/1.1
Host: webservice.webxml.com.cn
Content-Type: text/xml; charset=utf-8
Content-Length: 354
SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"
="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" cn/getMobileCodeInfo >
Modify PHP.ini
Remove the ";" before extension=php_soap.dll.
And restart apache
The PHP SoapClient class can be used to request WebService
$soap = <span>new</span> soapClient(<span>'</span><span>http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL</span><span>'</span><span>); print_r($soap</span>->getMobileCodeInfo( array(<span>'</span><span>mobileCode</span><span>'</span>=><span>'</span><span>13**********</span><span>'</span>) ) );
<span>Array ( [</span><span>0</span>] =><span> getMobileCodeInfoResponse getMobileCodeInfo(getMobileCodeInfo $parameters) [</span><span>1</span>] =><span> getDatabaseInfoResponse getDatabaseInfo(getDatabaseInfo $parameters) ) Array ( [</span><span>0</span>] => <span>struct</span><span> getMobileCodeInfo { </span><span>string</span><span> mobileCode; </span><span>string</span><span> userID; } [</span><span>1</span>] => <span>struct</span><span> getMobileCodeInfoResponse { </span><span>string</span><span> getMobileCodeInfoResult; } [</span><span>2</span>] => <span>struct</span><span> getDatabaseInfo { } [</span><span>3</span>] => <span>struct</span><span> getDatabaseInfoResponse { ArrayOfString getDatabaseInfoResult; } [</span><span>4</span>] => <span>struct</span> ArrayOfString {string string;
}
<span>//</span><span> 调用方法</span> print_r($soap->getMobileCodeInfo( array(<span>'</span><span>mobileCode</span><span>'</span>=><span>'</span><span>13426060134</span><span>'</span>) ) );Return results
stdClass Object ( [getMobileCodeInfoResult] => <span>13*********</span>:北京 北京 北京移动动感地带卡 )3 Build WebService server
What is wsdl?
wsdl is the specification of WebService.
<?xml version =<span>'</span><span>1.0</span><span>'</span> encoding =<span>'</span><span>UTF-8</span><span>'</span> ?> <definitions name=<span>'</span><span>自定义名称[可选]</span><span>'</span><span> targetNamespace</span>=<span>'</span><span>命名空间[一般为URL]</span><span>'</span><span> xmlns:tns</span>=<span>'</span><span>命名空间[值同targetNamespace]</span><span>'</span><span> xmlns:soap</span>=<span>'</span><span>http://schemas.xmlsoap.org/wsdl/soap/</span><span>'</span><span> xmlns:xsd</span>=<span>'</span><span>http://www.w3.org/2001/XMLSchema</span><span>'</span><span> xmlns:soapenc</span>=<span>'</span><span>http://schemas.xmlsoap.org/soap/encoding/</span><span>'</span><span> xmlns:wsdl</span>=<span>'</span><span>http://schemas.xmlsoap.org/wsdl/</span><span>'</span><span> xmlns</span>=<span>'</span><span>http://schemas.xmlsoap.org/wsdl/</span><span>'</span>> <!--<types> 元素定义 web service 使用的数据类型,WSDL 使用 XML Schema 语法来定义数据类型,也可以自定义Schema不包含的类型--> <types> <xsd:schema xmlns:xsd=<span>"</span><span>http://www.w3.org/2001/XMLSchema</span><span>"</span><span> targetNamespace</span>=<span>"</span><span>[值同上tns]</span><span>"</span>> </xsd:schema> </types> <!-- <message><span> 元素可定义每个消息的部件,以及相关联的数据类型. </span>--> <message name=<span>'</span><span>操作名Request</span><span>'</span>> <part name=<span>"</span><span>term</span><span>"</span> type=<span>"</span><span>xsd:string</span><span>"</span>/> </message> <message name=<span>'</span><span>操作名Response</span><span>'</span>> <part name=<span>"</span><span>value</span><span>"</span> type=<span>"</span><span>xsd:string</span><span>"</span>/> </message> <!-- <portType><span> 元素是最重要的 WSDL 元素.它可描述一个 web service、可被执行的操作,以及相关的消息. 它告诉你去哪个WebService的连接点,扮演了一个控制者. </span>--> <portType name=<span>'</span><span>操作列表名</span><span>'</span>> <operation name=<span>'</span><span>操作名</span><span>'</span>> <input message=<span>'</span><span>tns:操作名Request</span><span>'</span>/> <output message=<span>'</span><span>tns:操作名Response</span><span>'</span>/> </operation> </portType> <!--<binding> 元素为每个端口定义消息格式和协议细节--> <binding name=<span>'</span><span>WS下的频道名称</span><span>'</span> type=<span>'</span><span>tns:频道下的操作列表</span><span>'</span>> <!--style:属性可取值 <span>"</span><span>rpc</span><span>"</span> 或 <span>"</span><span>document</span><span>"</span>,ransport:属性定义了要使用的 SOAP 协议.在这个例子中我们使用 HTTP--> <soap:binding style=<span>'</span><span>rpc</span><span>'</span><span> transport</span>=<span>'</span><span>http://schemas.xmlsoap.org/soap/http</span><span>'</span>/> <!--operation 元素定义了每个端口提供的操作符,对于每个操作,相应的 SOAP 行为都需要被定义--> <operation name=<span>'</span><span>test</span><span>'</span>> <soap:operation soapAction=<span>'</span><span>http://www.cwtservice.cn/newOperation/</span><span>'</span>/> <input> <soap:body use=<span>'</span><span>encoded</span><span>'</span> <span>namespace</span>=<span>'</span><span>urn:xmethods-delayed-quotes</span><span>'</span><span> encodingStyle</span>=<span>'</span><span>http://schemas.xmlsoap.org/soap/encoding/</span><span>'</span>/> </input> <output> <soap:body use=<span>'</span><span>encoded</span><span>'</span> <span>namespace</span>=<span>'</span><span>urn:xmethods-delayed-quotes</span><span>'</span><span> encodingStyle</span>=<span>'</span><span>http://schemas.xmlsoap.org/soap/encoding/</span><span>'</span>/> </output> </operation> </binding> <!--<service>包含一个或者多个port元素,每个port元素表示一个不同的Web服务--> <service name=<span>'</span><span>WebService名称[如weatherWS,shopWS]</span><span>'</span>> <port name=<span>'</span><span>WS下的频道名称[如cartSoap,购物车服务]</span><span>'</span> binding=<span>'</span><span>tns:[频道名,同左]</span><span>'</span>> <soap:address location=<span>'</span><span>http://[webservice地址]</span><span>'</span>/> </port> </service> </definitions>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.