PHP5 the various problem-solving methods encountered when invoking JAVA WebService

Source: Internet
Author: User
Tags soap uuid xmlns wsdl

Start Gank.

Service side:

spring3.0.5+cxf2.4,jdk1.6

The "should be" automatically generated WSDL file < server is not our >

Client:

PHP5.1.3

The first question I met:

Soap-error:encoding:object has no ' id ' property

But the API document says no ID is needed to view the contents of the WSDL file

<xs:complextype name= "seal" ><xs:sequence><xs:element name= "id" type= "xs:long"/><xs:element minoccurs= "0" name= "name" type= "Xs:long"/>

Consult the schema document, which includes the following:

With schemas, we can use the MaxOccurs and minoccurs properties to define the number of times an element might appear. MaxOccurs defines the maximum number of occurrences of an element, while minoccurs defines the minimum number of occurrences of an element. The default values for MaxOccurs and minoccurs are 1! (Well, is this a service-side problem?) Then I wrote a value, passed the ... )


PS: There is a small link in the middle, I went to see the source code of PHP ...

Functions in the PHP_ENCODING.C in soap Model_to_xml_object

static int Model_to_xml_object (xmlnodeptr node, sdlcontentmodelptr model, zval *object, int style, int strict tsrmls_dc)

A small piece of code


else if (model->min_occurs = 0) {
return 2;
} else {
if (strict) {
Soap_error1 (E_error, "Encoding:object has no '%s ' property", model->u.element->name);//obviously <span style= " Font-family:times New Roman; " > It! </span>
}
return 0;
}

I found out from here that the problem appeared on the min_occurs, so I solved the above problem (is not the other side is not very standard?) )


Second question:

Looks like we got no XML document

This is depressing, it's been solved for a long time

Has returned to the data, and then I grabbed the packet (seemingly there is a way to display the data directly), found that the returned data similar to the following format:


http/1.1 OK
server:apache-coyote/1.1
content-type:multipart/related; type= "Application/xop+xml"; boundary= "UUID:0C37C356-41DE-4361-9835-AB8DC023DCAC"; Start= "<root.message@cxf.apache.org>"; start-info= "Text/xml"
content-length:790
Date:tue, Dec 07:57:45 GMT


--uuid:0c37c356-41d E-4361-9835-AB8DC023DCAC
Content-type:application/xop+xml; charset=utf-8; type= "Text/xml";
Content-transfer-encoding:binary
Content-id: <root.message@cxf.apache.org>
<soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" ><soap:body><ns2:createsealresponse xmlns:ns2 = "http://service.api.seal.kx.knet.cn/" ><return><code>2003</code><date>2012-12-04 15:57:46.124</date><msg>logic error</msg><result>sfn004.cn: 瀵 stroll 笉 Feng 紝 Girls がくしゅくしゅしていて Fireworks accommodating 嶁 € wengjiang 彲 qi $ embroidery 绔 欌 € 濋 獙 Xuan 佹 湇 鍔 $ enemy  鍦 ㄥ 鏍 The fu Adze 屼 笉 鑳 through 啀 Rao ℃ Open 鍐 岋 紒 the </result><result><span style= "Font-family:times New Roman;" >zhjx922.com</sPan>: 瀵 stroll 笉 Feng 紝 girls がくしゅくしゅしていて Smoke accommodating 嶁 € wengjiang 彲 $ embroidery 绔 欌 € 濋 獙 佹 湇 鍔 $ enemy  鍦 ㄥ 鏍 The Adze of the pick-and-go-屼-笉 by 鑳 啀 Rao Open ℃ 鍐 岋 紒: Createsealresponse></soap:body></soap:envelope>
--uuid:0 c37c356-41de-4361-9835-ab8dc023dcac--
is obviously not XML. So the PHP boss has an error.

Ask each other, the answer is:

CXF set the following upload properties, the key point is that mtom,php SOAP extensions do not support this thing by default

<jaxws:properties>
<entry key= "mtom-enabled" value= "true"/>
</jaxws:properties>

Baidu,google can be implemented through the WSO2 WSF for PHP extension, to avoid trouble to continue to find ...

Look at the Official document introduction

Http://cn2.php.net/soap

There is a reply to help me solve the problem, the final solution is as follows:

/**
* Inherit SoapClient class, rewrite __dorequest method
* @author zhjx922
*/
Class Zsoapclient extends SoapClient
{
Public Function __dorequest ($request, $location, $action, $version, $one _way = 0)
{
$response = Parent::__dorequest ($request, $location, $action, $version, $one _way);

According to the actual situation to do processing ... , if it's the beginning of the <?xml, change it into <?xml.
$start =strpos ($response, ' <soap ');
$end =strrpos ($response, ' > ');
$response _string=substr ($response, $start, $end-$start + 1);
Return ($response _string);
}
}

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.