熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> PHP編程 >> 正文

PHP5 在調用 JAVA WebService 時遇到的各種問題解決方法

2022-06-13   來源: PHP編程 

  開始gank

  服務端

  Spring+CXFJDK

  “應該是”自動生成的wsdl文件<服務端不是我們的>

  客戶端

  PHP

  碰見的第一個問題

  SOAPERROR: Encoding: object has no id property

  但是API文檔上說不需要id查看wsdl文件內容

  <xs:complexType name="seal"><xs:sequence><xs:element name="id" type="xs:long"/><xs:element minOccurs="" name="name" type="xs:long"/>

  查閱schema文檔有如下內容

  通過 schema我們可使用 maxOccurs 和 minOccurs 屬性來定義某個元素可能出現的次數maxOccurs 定義某元素出現次數的最大值而 minOccurs 則定義某元素出現次數的最小值maxOccurs 和 minOccurs 的默認值都是 !(好吧這個是服務端的問題?然後自己隨便寫了個值通過了

  
PS中間有個小環節我盡然去看了PHP的源代碼

  SOAP中的php_encodingc裡面的函數 model_to_xml_object

  static int model_to_xml_object(xmlNodePtr node sdlContentModelPtr model zval *object int style int strict TSRMLS_DC)

  //一小段代碼

  
} else if (model>min_occurs == ) {
return ;
} else {
if (strict) {
soap_error(E_ERROR "Encoding: object has no %s property" model>uelement>name);//明顯就是<span style="fontfamily:Times New Roman;">它!</span>
}
return ;
}

  我是從這裡發現問題出現在min_occurs上所以才解決了上面問題(是不是對方不太規范?)

  
第二個問題

  looks like we got no XML document

  這個可是郁悶了解決了好久

  已經返回來數據了然後我抓包(貌似有方法可以直接顯示數據)發現返回的數據類似如下格式

  
HTTP/ OK
Server: ApacheCoyote/
ContentType: multipart/related; type="application/xop+xml"; boundary="uuid:ccdeabdcdcac"; start="<rootmessage@cxfapacheorg>"; startinfo="text/xml"
ContentLength:
Date: Tue Dec :: GMT


uuid:ccdeabdcdcac
ContentType: application/xop+xml; charset=UTF; type="text/xml";
ContentTransferEncoding: binary
ContentID: <rootmessage@cxfapacheorg>
<soap:Envelope xmlns:soap=":Body><ns:createSealResponse xmlns:ns="::</date><msg>Logic error</msg><result>sfncn:瀵逛笉璧鳳紝姝ゅ煙鍚嶁€滃彲淇$綉绔欌€濋獙璇佹湇鍔$敵璇鋒鍦ㄥ鏍鎬腑锛屼笉鑳藉啀娆℃敞鍐岋紒</result><result><span style="fontfamily:Times New Roman;">zhjxcom</span>:瀵逛笉璧鳳紝姝ゅ煙鍚嶁€滃彲淇$綉绔欌€濋獙璇佹湇鍔$敵璇鋒鍦ㄥ鏍鎬腑锛屼笉鑳藉啀娆℃敞鍐岋紒</result></return></ns:createSealResponse></soap:Body></soap:Envelope>
uuid:ccdeabdcdcac
明顯不是XML所以PHP老大就報錯了

  詢問對方答復是

  CXF設置了如下上傳屬性關鍵點就是MTOMPHP SOAP擴展默認是乎不支持這個玩意

  <jaxws:properties>
<entry key="mtomenabled" value="true" />
</jaxws:properties>

  baidugoogle 可以通過WSO WSF FOR PHP 擴展實現嫌棄麻煩繼續找

  看了一下官方文檔介紹

  有條回復幫我解決了最終解決方法如下

  /**
* 繼承SoapClient類重寫__doRequest方法
* @author zhjx
*/
class ZSoapClient extends SoapClient
{
public function __doRequest($request $location $action $version $one_way = )
{
$response = parent::__doRequest($request $location $action $version $one_way);

//根據實際情況做處理如果是<?xml開頭改成<?xml
$start=strpos($response<soap);
$end=strrpos($response>);
$response_string=substr($response$start$end$start+);
return($response_string);
}
}


From:http://tw.wingwit.com/Article/program/PHP/201311/21341.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.