問題描述
上下文/我想要的:
我在使用 SOAP 調(diào)用 Web 服務(wù)時(shí)遇到問題.這是我想調(diào)用的 WS 的相關(guān)部分的圖像:
(我自愿隱藏命名空間部分,這里不相關(guān))
我想通過 'Demande_de_mot_de_passe' 函數(shù)發(fā)送數(shù)據(jù)并從這個(gè)請(qǐng)求中獲取結(jié)果.
在下面的代碼中,這個(gè)請(qǐng)求是正確的(函數(shù)的名字好),我猜問題是我要發(fā)送的數(shù)據(jù)的格式.函數(shù)的調(diào)用是用這部分進(jìn)行的:
$client->Demande_de_mot_de_passe($soapVar);
我嘗試過的:
這是我嘗試過的代碼的相關(guān)部分(我自愿更改數(shù)據(jù)的值,但沒有其他任何內(nèi)容.括號(hào)沒有拼寫錯(cuò)誤,它關(guān)閉了函數(shù)和我沒有放在這里的類以保留相關(guān)部分):
$client = new SoapClient('URL_OF_THE_WS?WSDL', array('跟蹤' =>1、'編碼' =>'UTF-8','soap_version' =>SOAP_1_1,'類圖' =>數(shù)組('Demande_de_mot_de_passe_Input' => 'Demande_de_mot_de_passe_Input')));$donnesUtilisateur = 新的 Demande_de_mot_de_passe_Input;$donnesUtilisateur->Code_societe = '000';$donnesUtilisateur->Ident_type = 'A';$donnesUtilisateur->Ident_code = 'xxxxxx';$donnesUtilisateur->Dat_demande = '00000000';$donnesUtilisateur->Adr_mail = 'xxxxxx';$donnesUtilisateur->Adr_cpos = 'xxxxxx';$donnesUtilisateur->Nom = 'xxxxxx';$donnesUtilisateur->Prenom = 'xxxxxx';$donnesUtilisateur->Dat_naiss = '00000000';$namespace = 'URL_OF_NAMESPACE';$soapVar = new SoapVar($donnesUtilisateur, SOAP_ENC_OBJECT,'Demande_de_mot_de_passe_Input', $namespace);$result = $client->Demande_de_mot_de_passe($soapVar);打印_r($result);}}類 Demande_de_mot_de_passe_Input {公共 $Code_societe;公共 $Ident_type;公共 $Ident_code;公開 $Dat_demande;公共 $Adr_cpos;公共 $Adr_mail;公共 $Nom;公開 $Prenom;公開 $Dat_naiss;}
我也試過用這樣的數(shù)組傳遞一個(gè)對(duì)象的數(shù)組(沒有成功):
$donnesUtilisateur = ['Code_societe' =>'000','Ident_type' =>'一個(gè)','Ident_code' =>'xxxxxx','Dat_demande' =>'00000000','Adr_cpos' =>'xxxxxx','Adr_mail' =>'xxxxxx','Nom' =>'xxxxxx','Prenom' =>'xxxxxx','Dat_naiss' =>'00000000',];
和:
$donnesUtilisateur = (對(duì)象) ['Code_societe' =>'000','Ident_type' =>'一個(gè)','Ident_code' =>'xxxxxx','Dat_demande' =>'00000000','Adr_cpos' =>'xxxxxx','Adr_mail' =>'xxxxxx','Nom' =>'xxxxxx','Prenom' =>'xxxxxx','Dat_naiss' =>'00000000',];
我得到的錯(cuò)誤:
SoapFault:未收到Demande_de_mot_de_passe_Input"對(duì)象.在 SoapClient->__call() 中
如果我不明白,發(fā)送的數(shù)據(jù)格式不正確,但是當(dāng)我嘗試其他方式發(fā)送時(shí),它仍然報(bào)告同樣的錯(cuò)誤.
我讀過的文檔沒有成功:
(抱歉,帖子太長了,我希望它足夠清楚,如果需要,不要忘記詢問精度,在此先感謝您的幫助:))
在您的 WSDL 類型中,有一個(gè)名為 Demande_de_mot_de_passe
的序列,它使用名為 Demande_de_mot_de_passeRequest
的元素而不是 <代碼>Demande_de_mot_de_passe_Input.
來自 SoapUI 的打印描述了消息請(qǐng)求,但如果它是 document
樣式,則 Demande_de_mot_de_passe
是一種類型.另一方面,如果它是 RPC
是方法名稱.
如果是 RPC,您可以按如下所示進(jìn)行啟動(dòng).您應(yīng)該盡可能使用本機(jī)對(duì)象(SOAP 會(huì)更好地使用它們).stdObject 就足夠了:
$request = new stdClass();$ demande_de_mot_de_passeRequest->Code_societe = '000';$ demande_de_mot_de_passeRequest->Ident_type = 'A';$ demande_de_mot_de_passeRequest->Ident_code = 'xxxxxx';$ demande_de_mot_de_passeRequest->Dat_demande = '00000000';$ demande_de_mot_de_passeRequest->Adr_mail = 'xxxxxx';$ demande_de_mot_de_passeRequest->Adr_cpos = 'xxxxxx';$ demande_de_mot_de_passeRequest->Nom = 'xxxxxx';$ demande_de_mot_de_passeRequest->Prenom = 'xxxxxx';$ demande_de_mot_de_passeRequest->Dat_naiss = '00000000';$request->Demande_de_mot_de_passeRequest = $ demande_de_mot_de_passeRequest;$response = $client->Demande_de_mot_de_passe($request);
如果您的 SOAP 綁定是文檔,您只需添加一個(gè)名為 Demande_de_mot_de_passe
/** 變量 $demande_de_mot_de_passeRequest 如上創(chuàng)建 **/$ demande_de_mot_de_passe = new stdClass();$ demande_de_mot_de_passe->Demande_de_mot_de_passeRequest = $ demande_de_mot_de_passeRequest;$request->Demande_de_mot_de_passe = $ demande_de_mot_de_passe;$response = $client->Demande_de_mot_de_passe($request);
您的 WSDL 不需要列表/集合(這不是您的情況),因此您不需要使用 SoapVar 創(chuàng)建/解析變量.您可以閱讀其他示例(一個(gè)是我的,但它是葡萄牙語),另一個(gè)是關(guān)于 BOGUS 節(jié)點(diǎn)的:
http://forum.imasters.com.br/topic/535213-enviar-xml-via-soap/?p=2137411http://www.fischco.org/blog/2011/3/26/php-soapserver-objects-arrays-and-encoding.html
Context / What I want :
I'm facing an issue while calling a Webservice with SOAP. Here's an image the relevant part of the WS I want to call :
(I voluntarily hide the namespace part, not relevant here)
I want to send data through 'Demande_de_mot_de_passe' function and catch result from this request.
In the code below, this request is correct (the name of the function is good), I guess the problem is the formatting of the data I want to send. The call of the function is made with this part :
$client->Demande_de_mot_de_passe($soapVar);
What I've tried :
Here's the relevant part of the code I've tried ( I voluntarily change values of data but nothing else. There is no typo error with the brackets, it close the function and the class I didn't put here to keep the relevant part) :
$client = new SoapClient('URL_OF_THE_WS?WSDL', array(
'trace' => 1,
'encoding' => 'UTF-8',
'soap_version' => SOAP_1_1,
'classmap' => array('Demande_de_mot_de_passe_Input' => 'Demande_de_mot_de_passe_Input')
));
$donnesUtilisateur = new Demande_de_mot_de_passe_Input;
$donnesUtilisateur->Code_societe = '000';
$donnesUtilisateur->Ident_type = 'A';
$donnesUtilisateur->Ident_code = 'xxxxxx';
$donnesUtilisateur->Dat_demande = '00000000';
$donnesUtilisateur->Adr_mail = 'xxxxxx';
$donnesUtilisateur->Adr_cpos = 'xxxxxx';
$donnesUtilisateur->Nom = 'xxxxxx';
$donnesUtilisateur->Prenom = 'xxxxxx';
$donnesUtilisateur->Dat_naiss = '00000000';
$namespace = 'URL_OF_NAMESPACE';
$soapVar = new SoapVar($donnesUtilisateur, SOAP_ENC_OBJECT,'Demande_de_mot_de_passe_Input', $namespace);
$result = $client->Demande_de_mot_de_passe($soapVar);
print_r($result);
}
}
class Demande_de_mot_de_passe_Input {
public $Code_societe;
public $Ident_type;
public $Ident_code;
public $Dat_demande;
public $Adr_cpos;
public $Adr_mail;
public $Nom;
public $Prenom;
public $Dat_naiss;
}
I've also tried with passing array of casting an object with the array like this (without success) :
$donnesUtilisateur = [
'Code_societe' => '000',
'Ident_type' => 'A',
'Ident_code' => 'xxxxxx',
'Dat_demande' => '00000000',
'Adr_cpos' => 'xxxxxx',
'Adr_mail' => 'xxxxxx',
'Nom' => 'xxxxxx',
'Prenom' => 'xxxxxx',
'Dat_naiss' => '00000000',
];
and :
$donnesUtilisateur = (object) [
'Code_societe' => '000',
'Ident_type' => 'A',
'Ident_code' => 'xxxxxx',
'Dat_demande' => '00000000',
'Adr_cpos' => 'xxxxxx',
'Adr_mail' => 'xxxxxx',
'Nom' => 'xxxxxx',
'Prenom' => 'xxxxxx',
'Dat_naiss' => '00000000',
];
Error I get :
SoapFault: Did not receive a 'Demande_de_mot_de_passe_Input' object. in SoapClient->__call()
If I unterstand clearly, the formatting of data sent is not correct but when I try other way to send it, it still reporting the same error.
Docs I've read about without success :
http://www.fvue.nl/wiki/Php:_Soap:_How_to_add_attribute_to_SoapVar
http://grokbase.com/t/php/php-soap/066jkmcz2h/passing-objects-to-soap-server-complextype-classmap
EDIT
Here's a capture of the WS 'Demande_de_mot_de_passe' function call in SoapUI :
(Sorry for the long post, I hope it is clear enough, don't forget to ask about precisions if needed, thanks in advance for your help :) )
At your WSDL's type, there's a sequence named Demande_de_mot_de_passe
which use a element named Demande_de_mot_de_passeRequest
and not Demande_de_mot_de_passe_Input
.
Your print from SoapUI describe the message request, but if it's document
style, Demande_de_mot_de_passe
is a type. On the other hand if it's RPC
is the method name.
Starting if it's RPC you can do as showed below. You should use as native object as you can (SOAP will work better with they). A stdObject will be good enough:
$request = new stdClass();
$demande_de_mot_de_passeRequest->Code_societe = '000';
$demande_de_mot_de_passeRequest->Ident_type = 'A';
$demande_de_mot_de_passeRequest->Ident_code = 'xxxxxx';
$demande_de_mot_de_passeRequest->Dat_demande = '00000000';
$demande_de_mot_de_passeRequest->Adr_mail = 'xxxxxx';
$demande_de_mot_de_passeRequest->Adr_cpos = 'xxxxxx';
$demande_de_mot_de_passeRequest->Nom = 'xxxxxx';
$demande_de_mot_de_passeRequest->Prenom = 'xxxxxx';
$demande_de_mot_de_passeRequest->Dat_naiss = '00000000';
$request->Demande_de_mot_de_passeRequest = $demande_de_mot_de_passeRequest;
$response = $client->Demande_de_mot_de_passe($request);
If your SOAP binding is document, you just have to add a new upper level named Demande_de_mot_de_passe
/** The variable $demande_de_mot_de_passeRequest is created as above **/
$demande_de_mot_de_passe = new stdClass();
$demande_de_mot_de_passe->Demande_de_mot_de_passeRequest = $demande_de_mot_de_passeRequest;
$request->Demande_de_mot_de_passe = $demande_de_mot_de_passe;
$response = $client->Demande_de_mot_de_passe($request);
Your WSDL doesn't need a list/collections (it's not your case), so you don't need to create/parse variables with SoapVar. There's others examples that you can read about (one is mine, but it's in portuguese) and other is about the BOGUS node:
http://forum.imasters.com.br/topic/535213-enviar-xml-via-soap/?p=2137411 http://www.fischco.org/blog/2011/3/26/php-soapserver-objects-arrays-and-encoding.html
這篇關(guān)于Webservice SOAP 請(qǐng)求 - 發(fā)送的數(shù)據(jù)類型錯(cuò)誤的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!