Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-扩展SoapClient以处理SWA(带附件的SOAP)_Php_Soap - Fatal编程技术网

PHP-扩展SoapClient以处理SWA(带附件的SOAP)

PHP-扩展SoapClient以处理SWA(带附件的SOAP),php,soap,Php,Soap,我正在尝试处理来自JavaSOAP服务的SWA响应。在这种情况下,SWA响应是附加到XML末尾的二进制附件以及一些MIME头。我不能将WSO2用于依赖项需求限制 任何帮助都将不胜感激 // Input ------=_Part_42_539586119.1332526191981 Content-Type: text/xml; charset=UTF-8 Content-Transfer-Encoding: binary Content-Id: <03B4708A9544C182C43E

我正在尝试处理来自JavaSOAP服务的SWA响应。在这种情况下,SWA响应是附加到XML末尾的二进制附件以及一些MIME头。我不能将WSO2用于依赖项需求限制

任何帮助都将不胜感激

// Input

------=_Part_42_539586119.1332526191981
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <03B4708A9544C182C43E51D9ADA1E456>

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body> ... TRUNCATED XML SOAP RESPONSE ... </soapenv:Body></soapenv:Envelope>

------=_Part_42_539586119.1332526191981
Content-Type: image/png
Content-Transfer-Encoding: binary
Content-Id: <D637B1257E3E5EEA06AF0E45494F8448>

BINARY DATA GOES HERE


// End of input
为此使用一个新的方法。从那开始就很简单:

require_once('MimeMailParser.class.php');

class SwADownloadSoapClient extends SoapClient
{
    const ATTACHMENT_DIR = '/path/to/saved/attachments/';

    public function __doRequest(
        $request, $location, $action, $version, $one_way=0
    ) {
        // Issue the SOAP request as SoapClient would normall
        $sResult = parent::__doRequest(
                               $request, $location, $action, $version, $one_way);

        // Handle and parse MIME-encoded messages
        // @note We're not doing much inspection
        //       of the XML payload against the attachments ATM
        //       so not sure how greatly this lives up to the spec
        $sResult = $this->_parseMimeMessage($sResult);

        $oParser = new MimeMailParser();
        $oParser->setText($sResult);

        // Save the attachments
        $aAttachments = $oParser->getAttachments();
        foreach($aAttachments as $oAttachment) {
            $sFile = $oAttachment->filename;
            if($rFp = fopen(self::ATTACHMENT_DIR . $sFile, 'w')) {
                while($sBytes = $attachment->read())
                    fwrite($rFp, $sBytes);
                fclose($rFp);
            }
        }
    }
}

如果您想更正确地实现,您需要将MIME附件与SOAP XML进行匹配。

您应该提供更多信息,我不知道问题出在哪里。这些部分可能是编码的吗?它是有效的XML吗?你分析了吗?您是否尝试了一些错误日志记录?这是一个有趣的黑客风格的尝试,从标题中获取二进制附件。我也朝这个方向走了一段时间。你应该试着用一个函数来解析有效负载,而不是自己用正则表达式。我想知道一个下载和上传的解决方案。
require_once('MimeMailParser.class.php');

class SwADownloadSoapClient extends SoapClient
{
    const ATTACHMENT_DIR = '/path/to/saved/attachments/';

    public function __doRequest(
        $request, $location, $action, $version, $one_way=0
    ) {
        // Issue the SOAP request as SoapClient would normall
        $sResult = parent::__doRequest(
                               $request, $location, $action, $version, $one_way);

        // Handle and parse MIME-encoded messages
        // @note We're not doing much inspection
        //       of the XML payload against the attachments ATM
        //       so not sure how greatly this lives up to the spec
        $sResult = $this->_parseMimeMessage($sResult);

        $oParser = new MimeMailParser();
        $oParser->setText($sResult);

        // Save the attachments
        $aAttachments = $oParser->getAttachments();
        foreach($aAttachments as $oAttachment) {
            $sFile = $oAttachment->filename;
            if($rFp = fopen(self::ATTACHMENT_DIR . $sFile, 'w')) {
                while($sBytes = $attachment->read())
                    fwrite($rFp, $sBytes);
                fclose($rFp);
            }
        }
    }
}