我正在尝试将值传递给我的WSDL文件。 XML文件的部分如下所示:
<xs:element name="loginEx">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="req" type="ns1:loginExRequest"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="loginExResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="ns1:loginExResponse"/>
</xs:sequence>
</xs:complexType>
</xs:element>
用于登录的加载的xsd文件[SessionService?xsd = session.xsd]:
<xs:complexType name="loginExRequest">
<xs:sequence>
<xs:element name="applicationName" type="xs:string"/>
<xs:element name="companyName" type="xs:string"/>
<xs:element name="applicationPassword" type="xs:string"/>
<xs:element name="localPassword" type="xs:string"/>
<xs:element name="version" type="xs:string"/>
<xs:element minOccurs="0" name="certificate" type="xs:string"/>
</xs:sequence>
</xs:complexType>
我的PHP调用是这样的:
$wsdl = "http://xxxx/axis2/services/SessionService?wsdl";
try {
$soapClient = new SoapClient($wsdlsession, array(
'location' => "http://xxxx/axis2/services/SessionService?wsdl",
'soap_version' => SOAP_1_2,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 180
));
$session_param = array("localPassword" => 'password', "companyName" => "Demo Company", "applicationName" => "Demo Application", "applicationPassword" => "password");
$soapClient->LoginEx($session_param);
} catch (SoapFault $e) {
print_r($e);
}
返回的错误是soapenv:Receiver [detail]
我无法在soapClient中看到我的错误。我唯一能想到的是没有正确请求loginExRequest?
感谢任何帮助!
答案 0 :(得分:1)
尝试类似下面的内容..
步骤1:创建两个类来为WSSE标题创建结构
<?php
class clsWSSEAuth {
private $Username;
private $Password;
function __construct($username, $password) {
$this->Username=$username;
$this->Password=$password;
}
}
class clsWSSEToken {
private $UsernameToken;
function __construct ($innerVal){
$this->UsernameToken = $innerVal;
}
}
?>
步骤2:为用户名和密码创建肥皂变量
<?php
$username = 1111;
$password = 1111;
//Check with your provider which security name-space they are using.
$strWSSENS = "http://schemas.xmlsoap.org/ws/2002/07/secext";
$objSoapVarUser = new SoapVar($username, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
$objSoapVarPass = new SoapVar($password, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
?>
步骤3:为Auth类创建对象并传入soap var
<?php
$objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
?>
步骤4:使用Auth类的对象创建SoapVar
<?php
$objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
?>
步骤5:为令牌类创建对象
<?php
$objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth);
?>
步骤6:使用令牌类对象
创建SoapVar<?php
$objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
?>
步骤7:为“安全”节点创建SoapVar
<?php
$objSoapVarHeaderVal=new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'Security', $strWSSENS);
?>
步骤8:从安全性soapvar
创建标题对象<?php
$objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal,true, 'http://abce.com');
//Third parameter here makes 'mustUnderstand=1
//Forth parameter generates 'actor="http://abce.com"'
?>
步骤9:创建Soap客户端对象
<?php
$objClient = new SoapClient($WSDL, $arrOptions);
?>
步骤10:设置soapclient对象的标头
<?php
$objClient->__setSoapHeaders(array($objSoapVarWSSEHeader));
?>
第11步:最后调用方法
<?php
$objResponse = $objClient->__soapCall($strMethod, $requestPayloadString);
?>