更改 php 中的soap前缀

change soap prefixes in php(更改 php 中的soap前缀)
本文介绍了更改 php 中的soap前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在将一个肥皂网络服务从 .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) 解析器

你想要什么?

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

解决方案

  1. 目前没有本地 SoapServer API 方法来改变 SOAP 前缀
  2. 您可以捕获 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前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)