簡體   English   中英

將XML數據發送到WSDL

[英]Send XML data to WSDL

我使用下一個代碼:

<?php
include ('class.doLogin.php');  
// xml content
$xmlDocument = '<SOAP-ENV:Body>
        <mns1:doLogin xmlns:mns1="http://sphinx.dat.de/services/Authentication">
            <request>
                <customerLogin>1323863</customerLogin>
                <customerNumber>teltfran</customerNumber>
                <customerSignature>akEwRUF3TUNWeXFwazRLZlNzS3p5VE5NL3BQaXJpc1FiWW1OM0lEdGlCdjBNVmJ2RCtCSC9ma0laSEIxR3RWdQ0Kc1VHeVY3VnFTRCtiRVI1aXRhbFFoVTBaVGFNPQ0KPU1VUjg=</customerSignature>
                <interfacePartnerNumber>1323863</interfacePartnerNumber>
                <interfacePartnerSignature>jA0EAwMCoHVabOFMT5lgySuK+MYbVQs2qPAgq/QI3TpiuR3raZMh710KRctv2aPd31LmjBiWaM0WDQl0</interfacePartnerSignature>
            </request>
        </mns1:doLogin>
    </SOAP-ENV:Body>';

ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient(
            "http://www.dat.de:80/DATECodeSelection/services/Authentication?wsdl",
            array(
                'trace' => 1,
                'exceptions' => 1,
                'soap_version' => SOAP_1_1,
                'encoding' => 'ISO-8859-1',
                'features' => SOAP_SINGLE_ELEMENT_ARRAYS
            )
);



$xmlvar = new SoapVar(
            '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://sphinx.dat.de/services/Authentication" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >'.$xmlDocument.'</SOAP-ENV:Envelope>',
            XSD_ANYXML
);

$doLogin = new doLogin();
$doLogin->request[0] = new doLoginRequest();
$doLogin->request[0]->customerLogin = "1323863";
$doLogin->request[1]->customerNumber = "teltfran";
$doLogin->request[2]->customerSignature = "akEwRUF3TUNWeXFwazRLZlNzS3p5VE5NL3BQaXJpc1FiWW1OM0lEdGlCdjBNVmJ2RCtCSC9ma0laSEIxR3RWdQ0Kc1VHeVY3VnFTRCtiRVI1aXRhbFFoVTBaVGFNPQ0KPU1VUjg";
$doLogin->request[3]->interfacePartnerNumber = "1323863";
$doLogin->request[4]->interfacePartnerSignature = "jA0EAwMCoHVabOFMT5lgySuK+MYbVQs2qPAgq/QI3TpiuR3raZMh710KRctv2aPd31LmjBiWaM0WDQl0";



try {
    $params->xmlDocument = (object)$xmlvar;
    //$save_result = $client->doLogin($params);
    $client->doLogin($doLogin);
    echo "<pre>\n\n";
    echo "Result :\n";
    echo "</pre>";
} catch (SoapFault $e) {
    echo "SOAP Fault: ".$e->getMessage()."<br />\n";
}

?>

和class.doLogin.php的代碼

<?php
class doLoginRequest{
    public $customerLogin;
    public $customerNumber;
    public $customerSignature;
    public $interfacePartnerNumber;
    public $interfacePartnerSignature;
}

class doLogin{
    /* array<doLoginRequest> */
   public $request;


}
?>

但是出現錯誤:SOAP錯誤:SOAP錯誤:編碼:對象沒有'customerLogin'屬性-哪里出了問題? 我該如何解決我的錯誤? 如果可能,請告訴我哪里錯了?

謝謝

根據我使用示例代碼進行的測試,我還會收到一個AuthorizationException,指出授權失敗。

這使我相信原因是您使用的登錄詳細信息,否則,如果請求格式錯誤,您將得到一個完全不同的錯誤,例如:

SOAP-ERROR: Encoding: object has no 'request' property

要么

SOAP-ERROR: Encoding: object has no 'customerLogin' property

但是,在提供所有必填字段時,即

$client = new SoapClient('http://www.dat.de:80/DATECodeSelection/services/Authentication?wsdl');

$tmp = new stdClass();
$tmp->request = new stdClass();
$tmp->request->customerLogin = 1323863;
$tmp->request->customerNumber = 'teltfran';
$tmp->request->customerSignature = 'akEwRUF3TUNWeXFwazRLZlNzS3p5VE5NL3BQaXJpc1FiWW1OM0lEdGlCdjBNVmJ2RCtCSC9ma0laSEIxR3RWdQ0Kc1VHeVY3VnFTRCtiRVI1aXRhbFFoVTBaVGFNPQ0KPU1VUjg';
$tmp->request->interfacePartnerNumber = 1323863;
$tmp->request->interfacePartnerSignature = 'jA0EAwMCoHVabOFMT5lgySuK+MYbVQs2qPAgq/QI3TpiuR3raZMh710KRctv2aPd31LmjBiWaM0WDQl0';

try {
    var_dump($client->doLogin($tmp));
} catch (SoapFault $e) {
    var_dump($e);
}

您只需獲取一個AuthorizationFailed異常de.dat.sphinx.global.exception.AuthorizationException: Authorization failed

可能值得通過www.dat.de檢查您的憑據是否正確?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM