PHP 使用 soap 发送 XML 返回未知错误


PHP sending XML with soap returns unknown rerror

我正在尝试将带有肥皂的用户注册发送到另一台服务器。我正在使用DOMdocument创建一个xml,并且在保存XML之后,我正在运行肥皂,它应该返回一个带有注册ID的xml以及我在xml中发送的所有数据。但是肥皂返回未知错误。正是这样:stdClass Object ( [RegisztracioInsResult] => stdClass Object ( [any] => 5Unknown error ) )

这就是我发送 XML 的方式。

/*xml creation with DOMdocument*/
$xml = saveXML();
$url = 'http://mx.biopont.com/services/Vision.asmx?wsdl';
$trace = '1';
$client = new SoapClient($url, array('trace' => $trace, "exceptions" => 0, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS));
$params = $client->RegisztracioIns(array('xml' => $xml));
$print_r($params);

如果我单击此URL上的RegisztracioIns服务的描述 http://mx.biopont.com/services/Vision.asmx 它会显示以下内容:

POST /services/Vision.asmx HTTP/1.1
Host: mx.biopont.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://mx.biopont.com/services/RegisztracioIns"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <RegisztracioIns xmlns="http://mx.biopont.com/services/">
      <xml>string</xml>
    </RegisztracioIns>
  </soap:Body>
</soap:Envelope>

据此,我认为我正在正确上传,但也许不是,我对肥皂没有太多经验。

我错过了什么吗?我还尝试将xml保存到我的服务器,而不是使用file_get_contents()获取内容。但结果是一样的。

你应该能够做这样的事情:

$res = $client->__soapCall( 'RegisztracioIns', array('xml'=>'my string to send'));

让 wsdl 包装'my string to send'正确的标记中。

您正在做类似的事情,但我认为 wsdl 实际上并没有包装您尝试传递的字符串,而是不传递任何内容,从而导致未知错误。

您可以使用 $client->__getLastRequest(); 检查传出 xml。

(另外,您的代码中有一个小错别字,最后一行应该print_r($params);

如果做不到这一点,您可以尝试使用 SoapVar() 自己编写 xml 并将类型设置为 XSD_ANYXML。

当 wsdl 为您包装所有内容时,对我来说似乎更干净,但它比用头撞墙要好,直到它这样做。

我尝试用你的 wsdl 来做到这一点。试一试:

$wsdl = "http://mx.biopont.com/services/Vision.asmx?wsdl"; 
$client = new SoapClient($wsdl, array(  'soap_version' => SOAP_1_1,
                                    'trace' => true,
                                    )); 
try {
$xml = "<RegisztracioIns xmlns='http://mx.biopont.com/services/'>
            <xml>string</xml>
        </RegisztracioIns>";
$args= array(new SoapVar($xml, XSD_ANYXML)); 
$res = $client->__soapCall( 'RegisztracioIns', $args );
var_dump($res);
} catch (SoapFault $e) {
echo "Error: {$e}";
}
print_r($client->__getLastRequest());
print_r($client->__getLastResponse());

鉴于它是匈牙利语(我认为?因此,请告诉我这是否适合您。