我在yii2中使用SOAP,当我尝试处理soap调用时出现错误
这是我的肥皂要求:
$xmlInput = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.interfaces.sessions.uams.amdocs\" xmlns:util=\"http://utils.uams.amdocs\" xmlns:web=\"http://webservices.fw.jf.amdocs\"><soapenv:Header/><soapenv:Body><ws:createUser><ws:aCreateUserInfo><util:userId>" . strtoupper($Userid) . "</util:userId><util:effDate>" . $Effdate . "T00:00:09+07:00</util:effDate><util:expDate>" . $Expdate . "T00:00:09+07:00</util:expDate><util:password>" . $this->randomPassword(8) . "</util:password><util:userRoles><ws:item>" . $Role . "</ws:item></util:userRoles></ws:aCreateUserInfo><ws:_awsi_header><web:securedTicket>" . $Ticket . "</web:securedTicket></ws:_awsi_header></ws:createUser></soapenv:Body></soapenv:Envelope>";
最后我收到了这样的回复:
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server.userException</faultcode><faultstring>org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.</faultstring><detail><faultData><cause xsi:nil="true"/><exception xsi:nil="true"/><message>SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.</message></faultData><ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">ocsbrntapp4</ns1:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
有人可以帮我解决这个问题吗?谢谢
答案 0 :(得分:0)
尝试下载SOAP UI并从那里执行请求。您将很容易看到自己缺少的东西。
https://www.soapui.org/downloads/latest-release.html
SOAP UI会自动告诉您在发布到Web服务时xml应该是什么样子,因此很容易看出您在哪里犯了错误。
答案 1 :(得分:0)
您的问题可能是由错误的转义xml文件引起的。 请检查 $ xmlInput
根据你的代码,我会认为问题出在你的“$ this-&gt; randomPassword(8)”函数中,但是没有看到这个函数我只是假设。
如果你输出$ xmlInput并在那里看到非法的xml字符,你可以通过两种方式将它们转义。
1)$xmlInput = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.interfaces.sessions.uams.amdocs\" xmlns:util=\"http://utils.uams.amdocs\" xmlns:web=\"http://webservices.fw.jf.amdocs\"><soapenv:Header/><soapenv:Body><ws:createUser><ws:aCreateUserInfo><util:userId>" . strtoupper($Userid) . "</util:userId><util:effDate>" . $Effdate . "T00:00:09+07:00</util:effDate><util:expDate>" . $Expdate . "T00:00:09+07:00</util:expDate><util:password><![CDATA[" . htmlentities($this->randomPassword(8), ENT_XHTML, 'UTF-8') . "]]></util:password><util:userRoles><ws:item>" . $Role . "</ws:item></util:userRoles></ws:aCreateUserInfo><ws:_awsi_header><web:securedTicket>" . $Ticket . "</web:securedTicket></ws:_awsi_header></ws:createUser></soapenv:Body></soapenv:Envelope>";
2)$xmlInput = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ws=\"http://ws.api.interfaces.sessions.uams.amdocs\" xmlns:util=\"http://utils.uams.amdocs\" xmlns:web=\"http://webservices.fw.jf.amdocs\"><soapenv:Header/><soapenv:Body><ws:createUser><ws:aCreateUserInfo><util:userId>" . strtoupper($Userid) . "</util:userId><util:effDate>" . $Effdate . "T00:00:09+07:00</util:effDate><util:expDate>" . $Expdate . "T00:00:09+07:00</util:expDate><util:password><![CDATA[" . $this->randomPassword(8) . "]]></util:password><util:userRoles><ws:item>" . $Role . "</ws:item></util:userRoles></ws:aCreateUserInfo><ws:_awsi_header><web:securedTicket>" . $Ticket . "</web:securedTicket></ws:_awsi_header></ws:createUser></soapenv:Body></soapenv:Envelope>";
基本检查$ xmlInput的内容,并确保正确转义所有值。