Soap communication (gsoap serves as server and php serves as client)

Source: Internet
Author: User

The communication between gsoap and php on the Internet fails,

You can call one for your actual business.

Php client

<?phptry{    $soap = new SoapClient("http://127.0.0.1:8888/add?wsdl",array('location'=>"http://127.0.0.1:8888",'uri'=>"urn:add",'connection_timeout'=>3,));    var_dump($soap);    $p=array('num1'=>6,'num2'=>2, 'sum'=>$sum);    $result1 = $soap->add($p);    var_dump($result1);    echo $result1->sum;                                                                       }catch(SoapFault $e){    echo $e->getMessage();}catch(Exception $e){    echo $e->getMessage();}


Gsoap server

# Include "soapH. h "# include <windows. h> # include "add. nsmap "# define BACKLOG (100)/* Max. request backlog */dword winapi process_request (LPVOID *); int http_get (struct soap * soap); int main (int argc, char ** argv) {struct soap; struct soap * tsoap; const char * fmt = "accepts socket % d connection from IP % d. % d. % d. % d \ n "; soap_init (& soap); if (argc <2) {soap_serve (& soap); soap_destroy (& soap); soap _ End (& soap);} else {soap. send_timeout = 60; soap. recv_timeout = 60; soap. accept_timeout = 3600; soap. max_keep_alive = 100; soap. fget = http_get; DWORD tid; HANDLE hThread; int port = atoi (argv [1]); // first command-line arg is port SOAP_SOCKET m, s; m = soap_bind (& soap, NULL, port, BACKLOG); if (! Soap_valid_socket (m) exit (1); printf ("Socket connection successful % d \ n", m); for (;) {s = soap_accept (& soap ); if (! Soap_valid_socket (s) {if (soap. errnum) {soap_print_fault (& soap, stderr); exit (1);} printf ("server timed out \ n"); break;} printf (fmt, s, (soap. ip> 24) & 0xFF, (soap. ip> 16) & 0xFF, (soap. ip> 8) & 0xFF, soap. ip & 0xFF); tsoap = soap_copy (& soap); // make a safe copy if (! Tsoap) break; hThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) process_request, tsoap, 0, & tid); if (hThread = NULL) {printf ("can not create a thread for SOAP request processing. \ n "); exit (-1) ;}} soap_done (& soap); return 0 ;}dword WINAPI process_request (LPVOID * soap) {soap_serve (struct soap *) soap); soap_destroy (struct soap *) soap); soap_end (struct soap *) soap); soap_done (struct so Ap *) soap); free (soap); return 0;} // implementation code of the Service Message int ns _ add (struct soap * add_soap, int num1, int num2, int * sum) {* sum = num1 + num2; return SOAP_ OK;} int http_get (struct soap * soap) {FILE * fd = NULL; printf ("call http_get. \ n "); char * s = strchr (soap-> path ,'? '); Printf ("call http_get2. \ n"); if (! S | strcmp (s ,"? Wsdl ") return SOAP_GET_METHOD; printf (" call http_get3. \ n "); fd = fopen (". /add. wsdl "," rb "); // fd = fopen (" F: // soap_server // add. wsdl "," rb "); if (! Fd) return 404; printf ("call http_get4. \ n "); soap-> http_content =" text/xml "; soap_response (soap, SOAP_FILE); printf (" call http_ge5. \ n "); for (;) {size_t r = fread (soap-> tmpbuf, 1, sizeof (soap-> tmpbuf), fd); if (! R) break; if (soap_send_raw (soap, soap-> tmpbuf, r) break;} fclose (fd); soap_end_send (soap); return SOAP_ OK ;}


This article is from the "djshell" blog. For more information, contact the author!

Related Article

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.