PHP soap instance

Source: Internet
Author: User

Copyright statement: original works can be reproduced. During reprinting, you must mark the original publication, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Http://blog.csdn.net/mayongzhan-ma yongzhan, myz, mayongzhan

SERVER + client + WSDL

Statement: Very simple !!!!!!

Refer to the following:

Http://blog.csdn.net/phphot/archive/2007/07/15/1692109.aspx

Create the server first, and then use the WSDL tool to generate the WSDL. I use Zend development environment,

In tools in zde, the WSDL generator wizard

The first page is the name, and the output address (after the output is moved directly, OK)

The second page is the class and address. The class is checked, and the URL adds the address of the Server File.

Page 3 finish

Don't forget to copy the WSDL...

Remember that no output exists in the class file referenced by the server.

There are two addresses to be added.

One is the description http: // 127.0.0.1/test/culculatorserver. php In WSDL.

One is the connection http: // 127.0.0.1/test/culculator. WSD in the client.

Class File

<? PHP

/**

* @ Name culculator. php

* @ Date Fri Jan 25 12:43:40 CST 2008

* @ Copyright Ma yongzhan (myz)

* @ Author ma yongzhan (myz)

* @ Link http://blog.csdn.net/mayongzhan/

*/

 

Class culculator

{

/**

* Sum

*

* @ Param float $ x

* @ Param float $ y

* @ Return float

*/

Public Function add ($ X, $ Y)

{

Return $ x + $ Y;

}

}

?>

 

Server

 

<? PHP

/**

* @ Name culculatorserver. php

* @ Date Fri Jan 25 12:44:04 CST 2008

* @ Copyright Ma yongzhan (myz)

* @ Author ma yongzhan (myz)

* @ Link http://blog.csdn.net/mayongzhan/

*/

 

Include ('./culator. php ');

$ Server = new soapserver ('./culculator. WSDL ');

$ Server-> setclass ('culator ');

$ Server-> handle ();

?>

 

Client

 

<? PHP

/**

* @ Name culculatorclient. php

* @ Date Fri Jan 25 12:43:54 CST 2008

* @ Copyright Ma yongzhan (myz)

* @ Author ma yongzhan (myz)

* @ Link http://blog.csdn.net/mayongzhan/

*/

 

$ Soap = new soapclient ('HTTP: // 127.0.0.1/test/culculator. WSDL ');

Echo $ soap-> Add (1, 2 );

?>

 

WSDL

 

<? XML version = '1. 0' encoding = 'utf-8'?>

 

<! -- WSDL file generated by Zend studio. -->

 

<Definitions name = "math" targetnamespace = "urn: math" xmlns: typens = "urn: math" xmlns: XSD = "http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://schemas.xmlsoap.org/wsdl/soap/" xmlns: soapenc = "http://schemas.xmlsoap.org/soap/encoding/" xmlns: WSDL = "http://schemas.xmlsoap.org/wsdl/" xmlns = "http://schemas.xmlsoap.org/wsdl/">

<Message name = "add">

<Part name = "X" type = "XSD: float"/>

<Part name = "Y" type = "XSD: float"/>

</Message>

<Message name = "addresponse">

<Part name = "addreturn" type = "XSD: float"/>

</Message>

<Porttype name = "culculatorporttype">

<Operation name = "add">

<Documentation>

Sum

</Documentation>

<Input message = "typens: Add"/>

<Output Message = "typens: addresponse"/>

</Operation>

</Porttype>

<Binding name = "culculatorbinding" type = "typens: culculatorporttype">

<Soap: Binding style = "RPC" Transport = "http://schemas.xmlsoap.org/soap/http"/>

<Operation name = "add">

<Soap: Operation soapaction = "urn: culculatoraction"/>

<Input>

<Soap: Body namespace = "urn: math" use = "encoded" encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/"/>

</Input>

<Output>

<Soap: Body namespace = "urn: math" use = "encoded" encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/"/>

</Output>

</Operation>

</Binding>

<Service name = "mathservice">

<Port name = "culculatorport" binding = "typens: culculatorbinding">

<Soap: address location = "http: // 127.0.0.1/test/culculatorserver. php"/>

</Port>

</Service>

</Definitions>

 

 

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.