改变php中的soap前缀

fre*_*gas 10 php soap

我正在从.net到php重写soap web服务.默认情况下,php给我的标签看起来像这样:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Header><ns1:FindAllCategories/></SOAP-ENV:Header><SOAP-ENV:Body><ns1:FindAllCategoriesResponse><ns1:FindAllCategoriesResult><ns1:ArtistCategoryDto>
Run Code Online (Sandbox Code Playgroud)

等等...

但我需要这个:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><FindAllCategoriesResponse xmlns="http://tempuri.org/"><FindAllCategoriesResult><ArtistCategoryDto>
Run Code Online (Sandbox Code Playgroud)

这类似于这里的问题:PHP和SOAP.改变信封, 但我不想像他那样破解它.此外,我正在创建一个将由现有的iphone应用程序使用的soap服务,而不是使用PHP来使用SoapClient来使用soap服务.iPhone应用程序只解析原始xml,我现在无法更改iPhone应用程序.

Cec*_*org 5

重新阅读你想要的东西,并在这里搜索php文档是我的解决方案和我做的几个假设

假设

  • 如果我是正确的,你知道SOAP前缀本身不是问题(只要它是一致的,你就可以使用任何前缀).
  • 我们需要为这个特定的Iphone应用程序创建一个解决方案,该应用程序使用当前无法修改/升级的(xml)解析器

你想要什么?

  1. 您希望使用本机API来更改SOAP前缀
  2. 您希望捕获SoapServer响应,以便在返回之前更改SOAP前缀

  1. 目前,没有用于更改SOAP前缀的本机SoapServer API方法
  2. 您可以通过regex或xml解析器捕获SoapServer响应并处理响应,请参阅下面的示例
<?php

// Create you parse function - Regex
function SoapServerRegexParser($input)
{
    // $input contains your XML Response
    // Do str_replace or preg_replace   
    $request = preg_replace({do replace});

    //return modified output to client
    return $request;
}

// OR create you parse function - Regex XML Parser
function SoapServerXMLParser($input)
{
    // $input contains your XML Response
    // Use any xml parser that you would like   
    $xml = new DOMDocument();
    $xml->formatOutput = true;
    $xml->preserveWhiteSpace = false;
    $xml->loadXML($input);
    //Do replacement have a looke at: DOMNode::replaceChild

    //return modified output to client
    return $xml->saveXML();
}

// Make php buffer all output
// Send all output to a callBack function

// Replace 'SoapServerRegexParser' with the callback function name of choice
ob_start('SoapServerRegexParser'); //buffer output and set callback function

// Create SoapServer
$server = new SoapServer('wsdlfile.wsdl');
$server->handle(); //Handle incoming request
ob_end_flush(); //Release buffer, but send through callback function first

?>
Run Code Online (Sandbox Code Playgroud)

这应该是技巧,我没有创建正则表达式部分或实际的xlm节点替换,但我想你可以自己做