【发布时间】:2021-04-06 21:36:22
【问题描述】:
我有一个在过去 5 年里工作的 php Web 服务 API。
我被要求将它码头化。所以我已经设置了我的 docker 容器。
除了我的肥皂服务器返回的响应之外,所有代码都可以正常工作。
所有代码都是一样的,没有任何改变,但现在 API 在 docker 中运行。
在 docker 外运行 API 时,我得到以下对 soapUI(或 curl)的响应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://netmedservice.com/soap/executeCommand">
<SOAP-ENV:Body>
<ns1:executeCommandResponse>
<executeCommandResponse>
<ns1:ResponseInfo>
<ns1:MainResponseParams>
<ns1:Attributes>
<ns1:Name>status</ns1:Name>
<ns1:Value>SUCCESS</ns1:Value>
</ns1:Attributes>
</ns1:MainResponseParams>
<ns1:AdditionalResponseParams/>
</ns1:ResponseInfo>
</executeCommandResponse>
</ns1:executeCommandResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是我能得到的最简单的回应。 docker 内部的相同响应是这样的:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://netmedservice.com/soap/executeCommand">
<SOAP-ENV:Body>
<ns1:executeCommandResponse>
<executeCommandResponse/>
</ns1:executeCommandResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如您所见,我有 wsdl 中描述的结构,但从 xsd 中我只得到第一个没有数据的元素。 在我的代码中,我尝试调试并查看是否有数据。 我有一个函数可以获取数组中的数据并创建相应的肥皂:
public static function soapEncodeNameValues(array $data, $soapContainer, $ns, $parentName="Attributes", $keyName="Name", $valName="Value") {
$dataStruct = new stdClass();
$paramStruct = new ArrayObject;
foreach ($data as $key => $val) {
error_log("Process Pair key-val : " . trim($key) . " - " . trim($val) . "\n");
$dataInStruct = new ArrayObject();
$dataInStruct[] = new SoapVar(trim($key), XSD_STRING, null, null, trim($keyName), $ns);
$dataInStruct[] = new SoapVar(trim($val), XSD_STRING, null, null, trim($valName), $ns);
$paramStruct[] = new SoapVar($dataInStruct, SOAP_ENC_OBJECT, null, null, $parentName, $ns);
}
$dataStruct = new SoapVar($paramStruct, SOAP_ENC_OBJECT, null, null, $soapContainer, $ns);
return $dataStruct;
}
error_log 输出为Process Pair key-val : status - SUCCESS
构造最终的soap响应并返回它的函数是:
function constructResponse($response) {
$rspObj = new stdClass();
$dataStruct = new ArrayObject;
$dataInStruct = new ArrayObject;
$addParams = new ArrayObject;
$dataInStruct[] = parser::soapEncodeNameValues($response->MainResponseParams, 'MainResponseParams', $this->ns);
if ($response->AdditionalResponseParams !== null) {
foreach ($response->AdditionalResponseParams as $addParam) {
$addParams[] = parser::soapEncodeNameValues($addParam, 'Lines', $this->ns, 'Attributes');
}
$dataInStruct[] = new SoapVar($addParams, SOAP_ENC_OBJECT, null, null, 'AdditionalResponseParams', $this->ns);
} else {
$dataInStruct[] = new SoapVar(null, SOAP_ENC_OBJECT, null, null, 'AdditionalResponseParams', $this->ns);
}
$dataStruct[] = new SoapVar($dataInStruct, SOAP_ENC_OBJECT, null, null, 'ResponseInfo', $this->ns);
$rspObj = new SoapVar($dataStruct, SOAP_ENC_OBJECT, null, null, 'executeCommandResponse', null);
error_log(print_r($rspObj,1));
return $rspObj;
}
上面编码的 SOAP 的错误日志是:
SoapVar Object
(
[enc_type] => 301
[enc_value] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => SoapVar Object
(
[enc_type] => 101
[enc_value] => status
[enc_name] => Name
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
[1] => SoapVar Object
(
[enc_type] => 101
[enc_value] => SUCCESS
[enc_name] => Value
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
)
)
[enc_name] => Attributes
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
[enc_name] => MainResponseParams
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
[1] => SoapVar Object
(
[enc_type] => 301
[enc_name] => AdditionalResponseParams
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
)
)
[enc_name] => ResponseInfo
[enc_namens] => http://netmedservice.com/soap/executeCommand
)
)
)
[enc_name] => executeCommandResponse
)
最后 xsd 模式中的响应是:
<xsd:complexType name="executeCommandResponse">
<xsd:sequence>
<xsd:element name="ResponseInfo" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="MainResponseParams" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Attributes" type="exc:AttributesList" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="AdditionalResponseParams" minOccurs="0" maxOccurs="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Lines" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Attributes" type="exc:AttributesList" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
谢谢
【问题讨论】:
标签: php docker soap php-7.4 soapserver