2009-07-13 14 views

उत्तर

10

देशी पीएचपी SoapClient वर्ग बहुखण्डीय संदेशों का समर्थन नहीं करता (और दृढ़ता से सभी WS- * मामलों में सीमित है) और मैं भी मुझे लगता है कि न तो पीएचपी लिखा पुस्तकालयों NuSOAP है और न ही Zend_Soap SOAP संदेश की इस तरह से निपटने कर सकते हैं।

मैं दो समाधान के बारे में सोच सकते हैं:

  • SoapClient वर्ग का विस्तार करने और SoapClient::__doRequest() विधि के ऊपर लिख वास्तविक प्रतिक्रिया स्ट्रिंग जिसे फिर आप अपने लहर में पार्स कर सकते हैं की पकड़ पाने के लिए।

    class MySoapClient extends SoapClient 
    { 
        public function __doRequest($request, $location, $action, $version, $one_way = 0) 
        { 
         $response = parent::__doRequest($request, $location, $action, $version, $one_way); 
         // parse $response, extract the multipart messages and so on 
        } 
    } 
    

    हालांकि यह कुछ हद तक मुश्किल हो सकता है - लेकिन कोशिश करने लायक है।

  • PHP के लिए एक अधिक परिष्कृत SOAP क्लाइंट लाइब्रेरी का उपयोग करें। मेरे दिमाग में आने वाला पहला और एकमात्र WSO2 WSF/PHP है जिसमें मूल PHP एक्सटेंशन स्थापित करने की लागत पर SOAP MTOM, WS-Addressing, WS-Security, WS-SecurityPolicy, WS-Secure Conversation और WS-ReliableMessaging शामिल हैं।

2

का उपयोग करते हुए एस Gehrig दूसरा विचार यहाँ ठीक काम किया।

में अधिकांश मामले, आपके पास एक MIME मल्टीपार्ट संदेश में पैक किया गया एकमात्र संदेश है। उन मामलों में एक "सोपफॉल्ट अपवाद: [क्लाइंट] ऐसा लगता है कि हमें कोई XML दस्तावेज़ नहीं मिला" अपवाद फेंक दिया गया है। यहां निम्न वर्ग को ठीक करना चाहिए:

class MySoapClient extends SoapClient 
{ 
    public function __doRequest($request, $location, $action, $version, $one_way = 0) 
    { 
     $response = parent::__doRequest($request, $location, $action, $version, $one_way); 
     // strip away everything but the xml. 
     $response = preg_replace('#^.*(<\?xml.*>)[^>]*$#s', '$1', $response); 
     return $response; 
    } 
} 
+0

मुझे लगता है कि "__doRequest" होना चाहिए "_doRequest"। – understack

0

बस पिछले सुझाए गए चरणों में और अधिक प्रकाश जोड़ने के लिए। आप प्रारूप निम्नलिखित में प्रतिक्रिया हो रही किया जाना चाहिए

--uuid:eca72cdf-4e96-4ba9-xxxxxxxxxx+id=108 
Content-ID: <http://tempuri.org/0> 
Content-Transfer-Encoding: 8bit 
Content-Type: application/xop+xml;charset=utf-8;type="text/xml" 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body> content goes here </s:Body></s:Envelope> 
--uuid:c19585dd-6a5a-4c08-xxxxxxxxx+id=108-- 

बस (मैं तो स्ट्रिंग कार्यों का उपयोग कर कि regex के साथ महान नहीं कर रहा हूँ)

public function __doRequest($request, $location, $action, $version, $one_way = 0) 
{ 
    $response = parent::__doRequest($request, $location, $action, $version, $one_way); 
    // strip away everything but the xml. 
    $response = stristr(stristr($response, "<s:"), "</s:Envelope>", true) . "</s:Envelope>"; 
return $response; 
} 
2

पीएचपी प्रलेखन से rafinskipg की सलाह का पालन करें कोड निम्न का उपयोग करें:

MTOM के लिए

समर्थन addign अपनी परियोजना के लिए इस कोड:

<?php 
class MySoapClient extends SoapClient 
{ 
    public function __doRequest($request, $location, $action, $version, $one_way = 0) 
    { 
     $response = parent::__doRequest($request, $location, $action, $version, $one_way); 
     // parse $response, extract the multipart messages and so on 

     //this part removes stuff 
     $start=strpos($response,'<?xml'); 
     $end=strrpos($response,'>');  
     $response_string=substr($response,$start,$end-$start+1); 
     return($response_string); 
    } 
} 

?> 

तो फिर तुम इस

<?php 
    new MySoapClient($wsdl_url); 
?> 
+0

हालांकि मुझे आपकी कोड शैली बिल्कुल पसंद नहीं है, फिर भी आप इस स्पष्ट कोड उदाहरण के साथ मेरे नायक हैं :) आकर्षण की तरह काम किया। हालांकि मुझे इसे एक लिट ट्विक करना पड़ा। मैं इसे एक नए जवाब में डाल दूंगा। – func0der

0

कर सकते हैं भले ही इस सवाल का जवाब यहाँ एक बहुत दिया गया है पहले से ही, मैं एक साथ डाल दिया है एक सामान्य समाधान यह बातें ध्यान में रखता है, कि XML आवरण के बिना आ सकता है।

class SoapClientExtended extends SoapClient 
{ 
    /** 
    * Sends SOAP request using a predefined XML 
    * 
    * Overwrites the default method SoapClient::__doRequest() to make it work 
    * with multipart responses. 
    * 
    * @param string $request  The XML content to send 
    * @param string $location The URL to request. 
    * @param string $action The SOAP action. [optional] default='' 
    * @param int $version The SOAP version. [optional] default=1 
    * @param int $one_way [optional] (If one_way is set to 1, this method 
    *       returns nothing. Use this where a response is 
    *       not expected.) 
    * 
    * @return string The XML SOAP response. 
    */ 
    public function __doRequest(
     $request, $location, $action, $version, $one_way = 0 
    ) { 
     $result = parent::__doRequest($request, $location, $action, $version, $one_way); 

     $headers = $this->__getLastResponseHeaders(); 

     // Do we have a multipart request? 
     if (preg_match('#^Content-Type:.*multipart\/.*#mi', $headers) !== 0) { 
      // Make all line breaks even. 
      $result = str_replace("\r\n", "\n", $result); 

      // Split between headers and content. 
      list(, $content) = preg_split("#\n\n#", $result); 
      // Split again for multipart boundary. 
      list($result,) = preg_split("#\n--#", $content); 
     } 

     return $result; 
    } 
} 

यह केवल काम करता है अगर आप विकल्प trace => true साथ SoapClientExtended आरंभ कर देगा।

0

कोड ने अभी भी "trace => true" विकल्प के साथ मेरे लिए काम किया है।

साझा करने के लिए धन्यवाद!

संबंधित मुद्दे