SOAP WSDL请求-方法返回错误的请求错误

我正在尝试进行肥皂呼叫,它返回“错误请求”错误。

示例调用为:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://centric.eu/services/CS/Trade/Standard/WS/" xmlns:cen="http://schemas.datacontract.org/2004/07/Centric.CS.Trade.Standard.WS.StockService.Contract.Request">
<soapenv:Header>
    <ws:Security soapenv:mustUnderstand="1" xmlns:ws="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <ws:usernameToken>
            <ws:username>username</ws:username>
            <ws:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</ws:Password>
         </ws:usernameToken>
    </ws:Security>
</soapenv:Header>
   <soapenv:Body>
      <ws:GetStock>
         <ws:request>
            <cen:StockRequests>
               <!--Zero or more repetitions:-->
               <cen:StockRequest>
                  <cen:CustomerNo>123</cen:CustomerNo>
                  <cen:Division>AGU_NL</cen:Division>
                  <cen:Item>113504</cen:Item>
                  <cen:Language>NL</cen:Language>
                  <cen:Login>123</cen:Login>
               </cen:StockRequest>
            </cen:StockRequests>
         </ws:request>
      </ws:GetStock>
   </soapenv:Body>
</soapenv:Envelope>

我使用以下代码:

$soapclient = new \SoapClient($url,array(
            'compression' => SOAP_COMPRESSION_accEPT | SOAP_COMPRESSION_GZIP | 9,'trace' => true,'exceptions' => 1,'cache_wsdl' => 1,));

$xml = '
        <ws:Security soapenv:mustUnderstand="1" xmlns:ws="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <ws:usernameToken>
                <ws:username>'.$username.'</ws:username>
                <ws:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">'.$password.'</ws:Password>
            </ws:usernameToken>
    </ws:Security>
        ';

        $soapheader = new \SoapHeader(
            'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd','Security',new \SoapVar($xml,XSD_ANYXML),true);
        $soapclient->__setsoapHeaders($soapheader);

try {
            $soapclient->__soapCall('GetStock',array(
                    'CustomerNo' => 123,'Division' => 'AGU_NL','Item' => '113504','Language' => 'NL','Login' => '123',)
            );
        } catch(\SoapFault $e) {
            echo '<pre>';
            print_r($e->getMessage());
            echo '</pre>';
        }

我得到的响应是:故障代码:HTTP,故障字符串:错误的请求 我不确定我是否创建了请求并正确调用了该方法。

任何帮助将不胜感激

谢谢

Hearbirds 回答:SOAP WSDL请求-方法返回错误的请求错误

最好不要尝试手动构造xml。尝试按照以下方式尝试一些方法:

$url = 'https://webservices.abcb2b.eu/Centric/CS/Trade/csprod/StockService.svc?wsdl';
$username = 'username';
$password = 'pass';
$client = new SoapClient($url,array('trace' => 1,"exception" => 0));

$wssNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
$usernameToken = new SoapVar(array(
    new SoapVar(array(
        new SoapVar($username,XSD_STRING,null,'Username',$wssNamespace),new SoapVar($password,'Password',$wssNamespace)
    ),SOAP_ENC_OBJECT,'UsernameToken',$wssNamespace)
),$wssNamespace);
$client->__setSoapHeaders(new SoapHeader($wssNamespace,'Security',$usernameToken));


try {
    $client->GetStock(array(
        'request' => array(
            'StockRequests' => array(
                'StockRequest' => array(
                    'CustomerNo' => 123,'Division' => 'AGU_NL','Item' => '113504','Language' => 'NL','Login' => '123',)
            )
        )
    ));
} catch(\SoapFault $e) {
    echo '<pre>';
    print_r($e->getMessage());
    echo '</pre>';
}
,

收到错误请求的原因是因为您的请求格式不正确,请尝试在请求之间没有空格

本文链接:https://www.f2er.com/2752548.html

大家都在问