PHP calls Java write WebService can not be solved by the argument problem

Source: Internet
Author: User
Tags soap wsdl

Preface:    

Just done a thing, PHP tune Java SOAP interface, but there is no document, only look at the previous written Java call to write. So Java can be called normally, the problem is that PHP can be transferred to the interface, but cannot receive parameters.

 

    began to understand the Java call, set targetnamespace what the Ghost, Go through the PHP manual, the English translation came to know, the soapvar corresponds to the encapsulation of the SOAP data.


Online, and found them all in a disorderly answer. Wasting my time, I might as well read the handbook myself.


The problem is: name Space


java soapclient:    

/** * saleorderinfo  for parameter ' {' Order ': ' 00122211111 ', ' Date ': ' 2017-04-14 ', ' customer_id ': ' 027 '} ';  */public string callwebservice (String saleorderinfo)  throws ServiceException,     remoteexception{// webservice Path            //  This adds no   "? wsdl"   effects are all the same            string endpoint =  "HTTP://127.0.0.1/SERVICE?WSDL";           //  Send SMS interface method name           String  operationname =  "Sendsaleorder";           string  targetNamespace =  "http://service.test.bb.service/";           //  Define service Objects            Org.apache.axis.client.service serVice = new org.apache.axis.client.service ();           //  Create a Call object           Call call  =  (call)  service.createcall ();          //  Set the destination address, which is the WebService path           call.settargetendpointaddress ( Endpoint);                   call.setoperationname (New qname (targetnamespace, operationname));                   call.addparameter ( New qname ("http://test.bb.service/",  "Saleorderinfo"),          xmltype.xsd_string, parametermode.in);          Call.setreturnclass (String.class);          //  fix error: Server failed to identify  HTTP  header   The value of soapaction            call.setusesoapaction (true);           call.setsoapactionuri ("");         object obj = call.invoke (New object[]{saleorderinfo});         string result = objectutils.tostring (obj);         if (Stringutils.isblank (result)) {         result =  "{\" message\ ": \" interface Returns the result is empty! \ ", \" retcode\ ": \" 0\ "}";         }   return result;}


Starting the wrong PHP call mode soapclient:

<?php//Specifies the WebService path and initializes a webservice client $ws = "HTTP://127.0.0.1/SERVICE?WSDL";//webservice service Address $client = new SoapClient ($WS);//Parameter $params = ' {' Order ': ' 00122211111 ', ' Date ': ' 2017-04-14 ', ' customer_id ': ' 027 '} '; $result = $client- >sendsaleorder ([saleorderinfo = $params]), echo "<pre>";p Rint_r ($result),//Display result//call succeeded, but parameter not received


The correct way to call PHP SoapClient:

<?php//Specifies the WebService path and initializes a WebService client $ws =  "HTTP://127.0.0.1/SERVICE?WSDL"; the address of the//webservice service $ client = new soapclient  ($WS);//Parameter $params =  ' {"Order": "00122211111", "Date": " 2017-04-14 "," customer_id ":" 027 "} '; $wrapper  = new StdClass; $wrapper->saleorderinfo =  new soapvar ($params, xsd_string,  "STRING",  "http://test.bb.service/",  " Saleorderinfo ", " http://test.bb.service/"), $searchrequest  = new soapparam ($wrapper, " Sendsaleorder "), $result = $client->sendsaleorder ($searchrequest);echo " <pre> ";p Rint_r ($result);// Display result//call succeeded 

after statement:

Yes, as you can see. The problem is that in the namespace, the service side sets the namespace of the method and parameters, but the namespace service side of the method sets the default address, so when the call is set the parameters of the namespace will be able to pass the parameter.


Soapvar is PHP open primarily to encapsulate the data used to put into a SOAP request, including naming methods.

This article is from the "Shows Technology" blog, be sure to keep this source http://wangzhijun.blog.51cto.com/9660708/1916427

PHP calls Java write WebService can not be solved by the argument problem

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.