调用SOAP服务器的应用程序。
如何将 xmlns:tns="http://schemas.xmlsoap.org/soap/encoding/" 添加到肥皂请求
我编写了一个调用soap服务的客户端,但它发送的请求不是我所期望的。 这是我的代码: 公共MessageResponse traGiayToHoSo(MessageRequest请求){ 留言乱七八糟...
我正在使用生成的连接服务(Soap)来生成签名。 服务器只期望消息在正文上签名。所以我需要提供 Body 的 Id 参考。 那里...
我无法将 SOAP 响应转换为 php 中的数组。 这是代码 $response = $client->__doRequest($xmlRequest,$location,$action,1); 这是 SOAP 响应。 我无法将 SOAP 响应转换为 php 中的数组。 这是代码 $response = $client->__doRequest($xmlRequest,$location,$action,1); 这是 SOAP 响应。 <soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:body> <searchflightavailability33response xmlns="http://FpwebBox.Fareportal.com/Gateway.asmx"> <searchflightavailability33result> <Fareportal><FpSearch_AirLowFaresRS><CntKey>1777f5a7-7824-46ce-a0f8-33d5e6e96816</CntKey><Currency CurrencyCode="USD"/><OriginDestinationOptions><OutBoundOptions><OutBoundOption segmentid="9W7008V21Feb14"><FlightSegment etc.... </searchflightavailability33result> </searchflightavailability33response> </soap:body> </soap:envelope>; 我使用以下方法转换为数组,但我得到空输出。 1.echo '<pre>';print_r($client__getLastResponse()); 2.echo '<pre>';print_r($response->envelope->body->searchflightavailability33response); 3.echo '<pre>';print_r($client->SearchFlightAvailability33($response)); 4.simplexml_load_string($response,NULL,NULL,"http://schemas.xmlsoap.org/soap/envelope/"); 5.echo '<pre>';print_r($client->SearchFlightAvailability33($response)); 请给我建议。 结合前面的方法,可以轻松地将以下 SOAP 响应结构转换为数组。仅使用函数“simplexml_load_string”删除冒号“:”在某些情况下返回 null。 SOAP 响应 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:transaccionResponse xmlns:ns2="http://ws.iatai.com/"> <respuestaTransaccion> <idTransaccion>94567</idTransaccion> <referencia>3958</referencia> <idEstado>3</idEstado> <nombreEstado>Declinada</nombreEstado> <codigoRespuesta>202</codigoRespuesta> <valor>93815.0</valor> <iva>86815.0</iva> <baseDevolucion>0.0</baseDevolucion> <isoMoneda>COP</isoMoneda> <fechaProcesamiento>24-07-2015 12:18:40 PM</fechaProcesamiento> <mensaje>REJECT</mensaje> <tarjetaRespuesta> <idFranquicia>1</idFranquicia> <nombreFranquicia>VISA</nombreFranquicia> <numeroBin>411111</numeroBin> <numeroProducto>1111</numeroProducto> </tarjetaRespuesta> <procesadorRespuesta> <idProcesador>3</idProcesador> </procesadorRespuesta> </respuestaTransaccion> </ns2:transaccionResponse> </S:Body> </S:Envelope> PHP 转换: $response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response); $xml = new SimpleXMLElement($response); $body = $xml->xpath('//SBody')[0]; $array = json_decode(json_encode((array)$body), TRUE); print_r($array); 结果: Array ( [ns2transaccionResponse] => Array ( [respuestaTransaccion] => Array ( [idTransaccion] => 94567 [referencia] => 3958 [idEstado] => 3 [nombreEstado] => Declinada [codigoRespuesta] => 202 [valor] => 93815.0 [iva] => 86815.0 [baseDevolucion] => 0.0 [isoMoneda] => COP [fechaProcesamiento] => 24-07-2015 12:18:40 PM [mensaje] => REJECT [tarjetaRespuesta] => Array ( [idFranquicia] => 1 [nombreFranquicia] => VISA [numeroBin] => 411111 [numeroProducto] => 1111 ) [procesadorRespuesta] => Array ( [idProcesador] => 3 ) ) ) ) 我找到了一个完美的解决方案来解析对数组的 SOAP 响应: $plainXML = mungXML( trim($soapXML) ); $arrayResult = json_decode(json_encode(SimpleXML_Load_String($plainXML, 'SimpleXMLElement', LIBXML_NOCDATA)), true); print_r($arrayResult); // FUNCTION TO MUNG THE XML SO WE DO NOT HAVE TO DEAL WITH NAMESPACE function mungXML($xml) { $obj = SimpleXML_Load_String($xml); if ($obj === FALSE) return $xml; // GET NAMESPACES, IF ANY $nss = $obj->getNamespaces(TRUE); if (empty($nss)) return $xml; // CHANGE ns: INTO ns_ $nsm = array_keys($nss); foreach ($nsm as $key) { // A REGULAR EXPRESSION TO MUNG THE XML $rgx = '#' // REGEX DELIMITER . '(' // GROUP PATTERN 1 . '\<' // LOCATE A LEFT WICKET . '/?' // MAYBE FOLLOWED BY A SLASH . preg_quote($key) // THE NAMESPACE . ')' // END GROUP PATTERN . '(' // GROUP PATTERN 2 . ':{1}' // A COLON (EXACTLY ONE) . ')' // END GROUP PATTERN . '#' // REGEX DELIMITER ; // INSERT THE UNDERSCORE INTO THE TAG NAME $rep = '$1' // BACKREFERENCE TO GROUP 1 . '_' // LITERAL UNDERSCORE IN PLACE OF GROUP 2 ; // PERFORM THE REPLACEMENT $xml = preg_replace($rgx, $rep, $xml); } return $xml; } // End :: mungXML() 它将为您提供完美的 SOAP XML 数据数组。 最后我找到了解决方案是 我们可以通过以下方式从 SOAP 获取响应正文 示例1: $xml = new SimpleXMLElement($soapResponse); foreach($xml->xpath('//soap:body') as $header) { $output = $header->registerXPathNamespace('default', 'http://FpwebBox.Fareportal.com/Gateway.asmx'); } 示例2: $doc = new DOMDocument('1.0', 'utf-8'); $doc->loadXML( $soapResponse ); $XMLresults = $doc->getElementsByTagName("SearchFlightAvailability33Response"); $output = $XMLresults->item(0)->nodeValue; Php 解析 SOAP 响应到数组 $xml = file_get_contents($response); // SimpleXML seems to have problems with the colon ":" in the <xxx:yyy> response tags, so take them out $xml = preg_replace(“/(<\/?)(\w+):([^>]*>)/”, “$1$2$3″, $xml); $xml = simplexml_load_string($xml); $json = json_encode($xml); $responseArray = json_decode($json,true); 我使用 DOMDocument 获得了一个值。 $soap_response = $client->__getLastResponse(); $dom_result = new DOMDocument; if (!$dom_result->loadXML($soap_response)) throw new Exception(_('Error parsing response'), 11); $my_val = $dom_result->getElementsByTagName('my_node')->item(0)->nodeValue; @gtrujillos 的第二个答案对我有用,但有一些更改,因为在我的情况下,json 字符串需要更多格式化代码,并且 xPath 需要采用这种方式“//S:Body”。这是最终解决我的问题的代码。我采用了相同的 SOAP 响应示例以及用于获取和返回 Soap 响应的代码,我在here:找到了它 PHP 转换 //getting the Soap Response header("Content-Type: text/xml\r\n"); ob_start(); $capturedData = fopen('php://input', 'rb'); $content = fread($capturedData, 5000); fclose($capturedData); ob_end_clean(); //getting the SimpleXMLElement object $xml = new SimpleXMLElement($content); $body = $xml->xpath('//S:Body')[0]; //transform to json $json = json_encode((array)$body); //Formatting the JSON $json = str_replace(array("\n","\r","?"),"",$Json); $json = preg_replace('/([{,]+)(\s*)([^"]+?)\s*:/','$1"$3":',$json); $Json = preg_replace('/(,)\s*}$/','}',$json); //Getting the array $array=json_decode($Json,true); //whatever yo need to do with the array ... //Return a Soap Response $returnedMsg=true;//this will depend of what do you need to return print '<?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> <notifications xmlns="http://soap.sforce.com/2005/09/outbound"> <Ack>' . $returnedMsg . '</Ack> </notifications> </soapenv:Body> </soapenv:Envelope>'; SOAP 可以被简单地理解为 XML,但您应该考虑命名空间。这对于 PHP 的 DOM 来说并不困难。在您的示例中,SOAP 使用内部节点的命名空间,并且 {http://FpwebBox.Fareportal.com/Gateway.asmx}searchflightavailability33result 元素包含另一个 XML 文档作为文本内容。 $xml = <<<'XML' <soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:body> <searchflightavailability33response xmlns="http://FpwebBox.Fareportal.com/Gateway.asmx"> <searchflightavailability33result> <Fareportal><FpSearch_AirLowFaresRS><CntKey>1777f5a7-7824-46ce-a0f8-33d5e6e96816</CntKey><Currency CurrencyCode="USD"/></FpSearch_AirLowFaresRS></Fareportal> </searchflightavailability33result> </searchflightavailability33response> </soap:body> </soap:envelope> XML; // define a constant for the namespace URI const XMLNS_FPW = 'http://FpwebBox.Fareportal.com/Gateway.asmx'; $document = new DOMDocument(); $document->loadXML($xml); $xpath = new DOMXpath($document); // register a prefix for the namespace $xpath->registerNamespace('fpw', XMLNS_FPW); // read the result element text content $result = $xpath->evaluate('string(//fpw:searchflightavailability33result)'); var_dump($result); // load the result string as XML $innerDocument = new DOMDocument(); $innerDocument->loadXML($result); $innerXpath = new DOMXpath($innerDocument); // read data from it var_dump($innerXpath->evaluate('string(//CntKey)')); 就我而言,我使用了 $body = $xml->xpath('//soapBody')[0]; $response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response); $xml = new SimpleXMLElement($response); $body = $xml->xpath('//SBody')[0]; $array = json_decode(json_encode((array)$body), TRUE); print_r($array); 对其中一个答案进行了小小的更改,因为我的 SOAP 响应有 s:Body 而不是 S:Body: $response1 = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response); $xml = new SimpleXMLElement($response1); $body = $xml->xpath('//sBody')[0]; $array = json_decode(json_encode((array)$body), TRUE); p_debug($array); $myfile = fopen("req_resposta.xml", "w") or die("Unable to open file!"); fwrite($myfile, $response1); fclose($myfile);
如何调用checkUser(param: ns1:UserAuthParam)等SOAP函数
我是 SOAP API 的新手。 目前我正在摸索中。 我正在尝试调用 SOAP 函数。 我有 WSDL 文件,其中包含以下代码: ...
我是肥皂服务的新手。我正在开发 Soap 客户端。 使用 Postman 成功命中 Soap 端点。请找到以下步骤 创建新集合并添加变量,如下所示
我在 Laravel 项目中使用 php 库 SoapClient 来获取 Web 服务的信息,该服务有时会在其 xml 中返回这种响应: � 当我测试...
在我的应用程序中,我需要访问内部(公司)Soap API。对于这种访问,我到目前为止使用的是 Zeep。但是现在访问必须通过代理并且 API 的实际地址已经......
IBM WebSphere Application 服务器 SOAP 连接器问题
任何人都可以帮我解决以下问题,我们正在使用 SOAP 连接器端口 8884 连接到 WebSphere 应用程序服务器,每天我们都会重新启动服务器, 但我们得到了...
创建一个提供 asmx 服务(SOAP API)的 Web 客户端
我需要从其他网页提供在第三方 asmx 服务中公开的数据,以便在我自己的 API 上使用它。我使用 NET 7.0 创建 API。要访问这个 asmx 服务的 URL,它需要一个先前的登录...
我使用 Lexis-Nexis SOAP 服务。 目前它适用于 Java 8 和 Lexis-Nexis v11。 但是后来我把Java升级到17版,生成了12版下的Lexis-Nexis SOAP服务客户端....
使用 .NET 中的 Soap Web 服务:无法解析签名 URI“#MsgBody”来计算隐式值
我在 .NET 中开发了一个测试客户端来连接到 SOAP web 服务(我无权访问服务器代码): 使用 fiddler,我得到了成功的响应,我能够看到响应混乱......
使用 netsuite php 获取与工作单相关的所有注释?
您好,我正在使用 php 工具包获取带注释的工单记录 现在我只获取工单记录,没有响应中的注释 这是代码 $workorderId = '5504'; $请求=新的\
我如何使用 SOAP 向 AzerothCore、Mangos、Cmangos Vmangos 或任何其他 wow 模拟器发送命令?
请向我解释如何在 asp.net、spring boot 或在 json http 请求中通信的任何类型的 rest api 中使用 soap 和 rest api。我只找到了 php 的解决方案,但我怀疑我...
SOAP 不使用 simplexml_load_String 提取子节点
我正在尝试获取 SOAP 数组/对象,但出现错误,我也尝试了名称空间。 但以下是在其他 XML 响应中对我有用的代码,在此处不起作用。 请指导我的错误...
我想使用自定义标识符记录 SOAP::Lite 传输请求/响应内容(例如下面示例中的事务 ID 或 txn_id): #!/usr/bin/perl 使用严格; 使用警告; 使用大...
在PHP本地soapClient中的SoapRequest格式化。
使用SoapClient的奇怪情况 我有以下代码来启动一个简单的soap请求。$client = new \SoapClient($this->wsdlURI, [ 'trace' => 1, 'cache_wsdl' ...
Apache CXF服务。如何在没有@HandlerChain注解的情况下配置处理程序链?
我尝试了以下代码。Resolver Class: public class WorkdayHandlerResolver implements HandlerResolver { private List. handlerChain = new ArrayList (); 公共...
Asp.Net Core 2.0 WCF Client CustomBinding PlatformNotSupportedException: 不支持BuildChannelFactoryCore
我需要能够在Asp.Net Core 2.0中使用自定义绑定在客户端发送授权。在Asp.net 4.6.1中可以工作,但在Core 2.2中不能工作。我正试图连接到Workday公共网络...
我试图使用SoapClient的扩展类来获取MTOM的二进制内容(这是一个PDF),这是一个参考类:https:/github comdebussMTOMSoapClientblobmasterMTOMSoapClient。这是参考类:https:/github.comdebussMTOMSoapClientblobmasterMTOMSoapClient.php ...
通过使用linq to xml过滤掉属性,将Type投影为类对象
如果我有一个xml soap文档,并且我想获取按属性细分的data(element),则如何过滤出属性并将过滤器数据转换为类。公开课报告{...