問題描述
我正在將一個肥皂網絡服務從 .net 重寫為 php.默認情況下,php 給我的標簽如下所示:
i'm rewriting a soap web service from .net to php. by default, php is giving me tags that look like this:
<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>
等等...
但我需要這個:
<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>
這類似于這里的問題:PHP AND SOAP.改變信封 但是我不想像他那樣破解它.此外,我正在創建一個將由現有 iphone 應用程序使用的肥皂服務,而不是使用 PHP 來使用 SoapClient 使用肥皂服務.iphone 應用程序只是解析原始 xml,我現在無法更改 iphone 應用程序.
This is similar to the question here: PHP AND SOAP. Change envelope however i'd like to not hack it the way he did. Also, i am creating a soap service that will be consumed by an existing iphone app, not using PHP to consume a soap service using SoapClient. The iphone app just parses the raw xml and i can't change the iphone app right now.
推薦答案
在重新閱讀您想要的內容并搜索 php 文檔后,這里是我的解決方案和我所做的一些假設
After re-reading what it is you want and searching through the php documentation here is my solution and a couple of assumptions that I made
假設
- 如果我是對的,您知道 SOAP 前綴本身不是問題(只要前綴一致,您就可以使用任何前綴).
- 我們需要為這個特定的 Iphone 應用創建一個變通方法,該應用使用當前無法由您修改/升級的 (xml) 解析器
你想要什么?
- 您想使用本機 API 來更改 SOAP 前綴
- 您想捕獲 SoapServer 響應,以便在返回之前更改 SOAP 前綴
解決方案
- 目前沒有本地 SoapServer API 方法來改變 SOAP 前綴
- 您可以捕獲 SoapServer 響應并通過正則表達式或 xml 解析器處理響應,請參見下面的示例
<?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
?>
這應該可以解決問題,我還沒有創建正則表達式部分或實際的 xlm 節點替換,但我認為你可以自己做
This should do the trick, I haven't created the regex part or the actual xlm node replacement but I figure you can do that yourself
這篇關于更改 php 中的soap前綴的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!