1

我是 SOAP 新手,我遇到了一些问题(是的,我已经搜索过 - 广泛,但我似乎无法满足我非常简单的要求 - 发送单个 XML 字符串)将一些输出发送到 .NET 服务器匹配这个:

    POST /someurl.asmx HTTP/1.1
Host: www.somehost.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://somehost.com/SubmitCalls"

<?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>
    <SubmitCalls xmlns="http://somehost/">
      <request>string</request>
    </SubmitCalls>
  </soap:Body>
</soap:Envelope>

我的 nusoap 代码如下所示:

<?php
require_once('../lib/nusoap.php');

$bodyxml = '<?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>
<SubmitCalls xmlns="http://somehost/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<request>
<?xml version="1.0" encoding="UTF-8"?>
<bXML xmlns="http://somehost/Schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <From>
  <UserName>some username</UserName>
  <Password>some password</Password>
 </From>
 <Calls>
  <Call>
   <Reference>11111</Reference>
   <Name>Joe Bloggs</Name>
   <Tel1>02075574200</Tel1>
   <Tel2>02075574201</Tel2>
   <Tel3>02075574202</Tel3>
   <Tel4>02075574203</Tel4>
   <Tel5>02075574204</Tel5>
   <CLI>08448220640</CLI>
   <CallTime>09:00</CallTime>
   <FileName>02075574200_1</FileName>
  </Call>
 <Call>
   <Reference>11111</Reference>
   <Name>Joe Bloggs</Name>
   <Tel1>02075574200</Tel1>
   <Tel2>02075574206</Tel2>
   <Tel3>02075574207</Tel3>
   <Tel4>02075574208</Tel4>
   <Tel5>02075574209</Tel5>
   <CLI>08448220640</CLI>
   <CallTime>09:00</CallTime>
   <FileName>02075574200_2</FileName>
  </Call>
 </Calls>
</bXML>
</request>
</SubmitCalls>
</soap:Body>
</soap:Envelope>
';


$client = new nusoap_client("somehost?WSDL",true);
$err = $client->getError();
if ($err) {
 echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
 exit();
}

$client->soap_defencoding = 'utf-8';
$client->useHTTPPersistentConnection();
$client->setUseCurl($useCURL);
$bsoapaction = "http://somehost/SubmitCalls";
$result = $client->send($bodyxml, $bsoapaction);
// Check for a fault
if ($client->fault) {
 echo '<h2>Fault</h2><pre>';
 print_r($result);
 echo '</pre>';
} else {
 // Check for errors
 $err = $client->getError();
 if ($err) {
  // Display the error
  echo '<h2>Error</h2><pre>' . $err . '</pre>';
 } else {
  // Display the result
  echo '<h2>Result</h2><pre>';
  print_r($result);
  echo '</pre>';
 }
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Client Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
echo '<h2>Proxy Debug</h2><pre>' . htmlspecialchars($proxy->debug_str, ENT_QUOTES) . '</pre>';
?>

(显然,最终脚本中的所有 somehost 和用户名都是正确的)。我可以连接到 WSDL,阅读它,只有一种我感兴趣的方法(SubmitCalls),它只有一个部分,在 WSDL 模式中名为“参数”。上面抛出了一个 400 Bad request 错误——我哪里出错了?

我尝试使用 PHP SOAP,但我似乎无法将 XML 字符串作为 SOAP 请求的主体发送。在三天的大部分时间里,我一直在摆弄这个,并阅读了无数的网页,但我仍然无法做到正确。请帮助......如果你能告诉我如何使用任何一个库来做到这一点,我将非常感激......

4

4 回答 4

5

You can send plain XML with the $client->send() method.

$raw_xml = "<Your_XML>...</Your_XML>";
$msg = $client->serializeEnvelope("$raw_xml");
$result=$client->send($msg, $endpoint);

You can see the example here:

http://itworkarounds.blogspot.com/2011/07/send-raw-xml-with-php-nusoap.html

If that does't work you can try posting the XML with CURL.

于 2011-08-04T11:33:14.170 回答
3

-尝试这个-

$xml = simplexml_load_string('<data>x</data>')

然后(nusoap)

$result = $client->call('host', array('parameter' =>$xml)
于 2011-07-14T20:38:52.430 回答
1

不完全是这个问题的答案 - 但现在已经解决了。服务提供者创建了一个新方法,除了它允许使用 XML 文档而不是字符串之外,它在所有方面都是相同的。通过对 $bodyxml 变量的内容进行一些小改动,并将其发送到这个新方法,它似乎可以正常工作。

顺便说一句 - 任何想要调试 SOAP 应用程序的人都应该真正考虑从 Sourceforge 获取 SOAP UI。这确实帮助我理智地检查了我的问题,并为修复提供了一些有用的指示。

于 2010-11-22T18:07:38.893 回答
0

您始终可以将 xml 作为字符串发送并拧紧库。不推荐,但在某些情况下更容易。

不要忘记Header("SoapAction: ...")

于 2010-11-19T20:52:14.217 回答