如何删除Zend_Soap中的命名空间?

问题描述 投票:3回答:2

我正在尝试使用MyMemory的翻译网络服务:qazxsw poi

不幸的是,Zend_Soap_Client确实生成了服务无法识别的XML请求对象。我想这是因为标签内的ns1-Attribute(命名空间)。那么有谁知道如何删除它们?

这基本上就是我做的事情:

http://mymemory.translated.net/doc/spec.php

然后我调用函数:

$client = new Zend_Soap_Client('http://mymemory.translated.net/otms/?wsdl', array(
    'soap_version' => SOAP_1_1
));

生成的XML如下所示:

try {
    $client->otmsGet(array(
        'key' => 'xxx',
            'q' => array(
                'source' => 'Computer Science',
                'source_lang' => 'en-US',
                'target_lang' => 'de-DE'
            )
        ));
} catch(Exception $e) {
    print $client->getLastRequest();
}

它应该看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
    <SOAP-ENV:Body>
        <ns1:otmsGet>
            <ns1:key>xxx</ns1:key>
            <ns1:q>
                <ns1:source>Computer Science</ns1:source>
                <ns1:source_lang>en-US</ns1:source_lang>
                <ns1:target_lang>de-DE</ns1:target_lang>
            </ns1:q>
        </ns1:otmsGet>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

谢谢你的帮助!

php zend-framework soap wsdl zend-soap
2个回答
1
投票

我不得不创建一个包装器:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <otmsGet xmlns="http://tempuri.org/">
            <key xmlns:SOAPSDK1="http://tempuri.org/">mmDemo123</key>
            <q xmlns:SOAPSDK2="http://tempuri.org/">
                <source>control panel</source>
                <source_lang>en-US</source_lang>
                <target_lang>es-ES</target_lang>
            </q>
        </otmsGet>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

0
投票

对于Zend 2应用程序,您可以向控制器添加一个额外的类,以便立即替换soap请求。

例:

class My_Soap_Client_Namespace extends Zend_Soap_Client_Common {
    protected $namespace = null;

    function __construct($doRequestCallback, $wsdl, $options) {
            if (array_key_exists('namespace', $options)) {
                $this->namespace = $options['namespace'];
            }
            parent::__construct($doRequestCallback, $wsdl, $options);
    }

    function __doRequest($request, $location, $action, $version, $one_way = null) {
        if ($this->namespace != null) {
            $request = preg_replace ( '/<ns1:(\w+)/', '<$1 xmlns="' . $this->namespace . '"', $request, 1 );
            $request = preg_replace ( '/<ns1:(\w+)/', '<$1', $request );
            $request = str_replace ( array ('/ns1:', 'xmlns:ns1="' . $this->namespace . '"' ), array ('/', '' ), $request );
        }

        return parent::__doRequest ( $request, $location, $action, $version );
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.