webserver two modes
PHP 使用soap有两种方式。 一、用wsdl文件 服务器端。 <?php class service { public function HelloWorld() { return "Hello"; } public function Add($a,$b) { return $a+$b; } } $server=new SoapServer('soap.wsdl',array('soap_version' => SOAP_1_2)); $server->setClass("service"); $server->handle(); ?> 资源描述文件,可以用工具(zend studio)生成。其实就是一个xml文件。 <?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost/interface/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="soap" targetNamespace="http://localhost/interface/"> <wsdl:types> <xsd:schema targetNamespace="http://localhost/interface/"> <xsd:element name="HelloWorld"> <xsd:complexType> <xsd:sequence> <xsd:element name="in" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="HelloWorldResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="out" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="Add"> <xsd:complexType> <xsd:sequence> <xsd:element name="in" type="xsd:int"></xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="AddResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="out" type="xsd:int"></xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types> <wsdl:message name="AddRequest"> <wsdl:part name="a" type="xsd:int"></wsdl:part> <wsdl:part name="b" type="xsd:int"></wsdl:part> </wsdl:message> <wsdl:message name="AddResponse"> <wsdl:part name="c" type="xsd:int"></wsdl:part> </wsdl:message> <wsdl:portType name="TestSoap"> <wsdl:operation name="Add"> <wsdl:input message="tns:AddRequest"></wsdl:input> <wsdl:output message="tns:AddResponse"></wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="soapSOAP" type="tns:TestSoap"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="Add"> <soap:operation soapAction="http://localhost/interface/Add" /> <wsdl:input> <soap:body use="literal" namespace="http://localhost/interface/" /> </wsdl:input> <wsdl:output> <soap:body use="literal" namespace="http://localhost/interface/" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="TestSoap"> <wsdl:port binding="tns:soapSOAP" name="soapSOAP"> <soap:address location="http://localhost/interface/myservice.php"/> </wsdl:port> </wsdl:service> </wsdl:definitions> 客户端调用 <?php $soap = new SoapClient('http://localhost/interface/soap.wsdl'); echo $soap->Add(1,2); ?> 二、不用wsdl文件 服务器端 <?php class service { public function HelloWorld() { return "Hello"; } public function Add($a,$b) { return $a+$b; } } $server=new SoapServer(null,array('uri' => "abcd")); $server->setClass("service"); $server->handle(); ?> 客户端 <?php try{ $soap = new SoapClient(null,array( "location" => "http://localhost/interface/soap.php", "uri" => "abcd", //资源描述符服务器和客户端必须对应 "style" => SOAP_RPC, "use" => SOAP_ENCODED )); echo $soap->Add(1,2); }catch(Exction $e){ echo print_r($e->getMessage(),true); } ?>
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the two modes of webserver, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Alipay PHP...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.
