Webservice SOAP请求-发送的数据类型错误 [英] Webservice SOAP request - Wrong type of data sent
问题描述
上下文/我想要什么:
使用SOAP调用Web服务时遇到问题.这是我要调用的WS相关部分的图像:
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)
我想通过'Demande_de_mot_de_passe'函数发送数据并捕获该请求的结果.
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);
我尝试过的方法:
这是我尝试过的代码的相关部分(我自愿更改数据值,但没有其他更改.方括号中没有错别字错误,它关闭了函数和未在此处放置的类,以保持相关部分):
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',
];
和:
$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',
];
我收到错误:
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.
我读过的文档都没有成功:
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
编辑
以下是SoapUI中WS'Demande_de_mot_de_passe'函数调用的捕获:
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 :) )
推荐答案
在您的WSDL类型中,有一个名为Demande_de_mot_de_passe
的序列,该序列使用名为Demande_de_mot_de_passeRequest
而不是Demande_de_mot_de_passe_Input
的元素.
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
.
您从SoapUI上打印的内容描述了消息请求,但是如果它是document
样式,则Demande_de_mot_de_passe
是一种类型.另一方面,如果方法名称为RPC
.
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.
如果是RPC,则可以按如下所示进行操作.您应该尽可能地将其用作本机对象(SOAP可以更好地与它们一起使用).一个stdObject就足够了:
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);
如果您的SOAP绑定是文档,则只需添加一个名为Demande_de_mot_de_passe
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);
您的WSDL不需要列表/集合(不是您的情况),因此您不需要使用SoapVar创建/解析变量.您还可以阅读其他示例(一个是我的,但是是葡萄牙语),另一个是关于BOGUS节点的:
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
这篇关于Webservice SOAP请求-发送的数据类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!