Soap learning to build the actual message format

Source: Internet
Author: User

Because the need to do a SOAP interface docking, the other environment is not ready to grab the package, will only call do not understand the format structure, we just want to do a lightweight interface, do not need to support the specific SOAP format, only need to specify the interface specific parameter name, parse the string.

Therefore, it is necessary to determine the message format of SOAP by grasping packets, so as to make string parsing and message assembling easier.

So you're ready to build a PHP soap environment to grab packets.


Current environment

centos6.3 system, default PHP does not support soap, download the php5.6 version

Compile

./configure '--with-libxml-dir=/usr/lib '--with-zlib '--with-gd '--with-zlib-dir=/usr/local '--with-mysql '-- Enable-sockets '--enable-mbstring '--enable-soap '--enable-safe-mode '--enable-ftp '--with-png-dir=/usr/local ' '--with-freetype-dir=/usr/local '--with-jpeg-dir=/usr/local '--with-sqlite=shared '

found that the corresponding Iconv library is missing, it is estimated that it is not found in the default path.

So recompile the Iconv library, set the./configure--prefix=/usr/local/libiconv


Then compile PHP plus a word '--with-iconv=/usr/local/libiconv '

./configure '--with-libxml-dir=/usr/lib '--with-zlib '--with-gd '--with-zlib-dir=/usr/local '--with-mysql '-- Enable-sockets '--enable-mbstring '--enable-soap '--enable-safe-mode '--enable-ftp '--with-png-dir=/usr/local ' '--with-freetype-dir=/usr/local '--with-jpeg-dir=/usr/local '--with-sqlite=shared '--with-iconv=/usr/local/ Libiconv


Make

Make install


Php-m|grep Soap

Show installation Success


It's tragic to find that Apache's phpinfo use PHP or 5.3.3, replace/usr/bin/php as a new version, restart Apache, but not valid, using the old version of PHP. I haven't found a solution for half a day.


According to another method, set soap.so into php.ini, but found that PHP did not compile the library, there is only one opcache.so. According to the online method, ready to compile the PHP installation directory under the Ext/soap production so, found that even configure are not, is estimated to be the old version of the function. Originally wanted to find the 5.3.3 version, but the official position has not been so old version.


Check out the new PHP version of the Internet, found that the current PHP support built-in an HTTP server.

Php-s localhost:3300-t/path/to/root

You can start an HTTP service with a port of 3300, so you don't have to toss the damn Apache.


Follow the online process to build a server and client.

First, put the server.wsdl.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7F/52/wKioL1cZ4Vmw2399AABzw_M1TrQ849.png "title=" WSDL sample "alt=" Wkiol1cz4vmw2399aabzw_m1trq849.png "/>

Red returns the result, 2 parameters, one is the result one is the wrong reason, the type is wsdl:types, special toss, for this return value to get a half-day, the other side is using Java, also said not understand.

Cyan is an input parameter, 5 independent parameters, very simple.

Purple is the request address, after the client gets the WSDL, it will request data to this address.


Look at client2.php.

<?php$soap = new SoapClient ("service.wsdl"), $soap->testsoap ("1", "2", "3", 0, "4");? >

It is simple to pass in two sentences, passing 5 parameters through WSDL.


Look at server.php again.

Note that this is the URL address inside the purple box inside the WSDL.

<?phpclass Service {public Function testsoap ($a, $b, $c, $d, $e) {return 0;}} $server = new SoapServer (' service.wsdl ', Array (' soap_version ' = soap_1_2)); $server->setclass ("Service"); Register all methods of the service class $server->handle (); Processing Request?>

Also very simple.


Grab the packet and start PHP client2.php

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7F/52/wKioL1cZ4sWye_N0AABw-K6ihtg898.png "title=" Post incoming. png "alt=" wkiol1cz4swye_n0aabw-k6ihtg898.png "/> View packet packets, the format is simple, it is easy to build strings, parsing fixed parameters is not difficult.


But there is a problem, that is, the return value (0), the return value is not recognized. An estimated return of 0 seems to be no good.

Here, in the client, the format of the return value is printed.

<?php$soap = new SoapClient ("service.wsdl"); $a 1 = $soap->testsoap ("1", "2", "3", 0, "4"), Echo GetType ($a 1); echo "\ n"; Echo var_dump ($a 1);? >

Found to be Stdclass object, I made the following changes in function Testsoap

$andy = Array (), $andy = (object) $andy, $andy->a = +, $andy->b = "Hahahaha"; return $andy;

Although it is an object, but still wrong, the format is not correct, then this wsdl:types exactly what is a thing, behind the implementation of the map to try, finally is the experimental results.

$cardUID = Array (' Result ' = ' + ', ' errordescription ' = ' aaaaa '); return $cardUID;


Grab the bag as follows

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/7F/54/wKiom1cZ5YPAJVvrAAByhb_LXR0095.png "title=" answer. png "alt=" Wkiom1cz5ypajvvraabyhb_lxr0095.png "/> can see 100 and AAAAA.


In this way, the actual format of soap is also sweeping, but simply implement a few interfaces, with string assembly and parsing can be completed.




This article is from "Flying Justice Blog" blog, please be sure to keep this source http://xzq2000.blog.51cto.com/2487359/1766770

Soap learning to build the actual message format

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.