Я создал WS с JAX-WS.Я хочу получить переменную из WS, мой WS отлично работает с XML-запросом Postman.Но если я вызываю свой WS из PHP, я получаю NULL.Я не могу изменить код PHP, потому что не в моих руках.Поэтому я должен изменить свой код JAX-WS.
Я попытался изменить определения, но не смог, потому что WSDL самогенерируется JAX-WS.Я не знаю, где мне нужно установить определения "xmlns".Возможно, мне придется изменить определения WSDL, но я не совсем уверен, что это решит проблему.(jdk1.8.0_181 и PHP 7.2)
Код PHP:
$array = array('AppUser' => USER_HL7, 'Password' => KEY_HL7);
$json_array = json_encode($array);
$array_param = array('json_array' => $json_array);
$data = 'false';
try {
$soapClient = new SoapClient($url . '?wsdl', array('trace' => true, 'exceptions' => true));
$soapClient->__setLocation($url);
$response = $soapClient->__soapCall("checkin", $array_param);
echo "REQUEST:\n" . $soapClient->__getLastRequest() . "\n";
return $data = json_decode($response, true);
} catch (Exception $e) {
return $data;
}
Я изменил $array_param
на array($array_param)
и работает.но, как я уже сказал, я не могу изменить код PHP.Я должен изменить код Java.
JAVA func, json_array печатает NULL, когда $array_param
, но работает с array($array_param)
:
@WebMethod(operationName = "checkin")
public String checkin(@WebParam(name = "json_array") String json_array) {
//TODO implement this method
System.out.println(json_array);
return "ok";
}
WSDL, который работает с кодом PHP:
<?xml version="1.0" encoding="UTF-8" ?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="urn:interfaceliswebservice"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap14="http://schemas.xmlsoap.org/wsdl/soap14/"
name="interfacelis"
targetNamespace="urn:interfaceliswebservice">
<types>
<xsd:schema targetNamespace="urn:interfacelis">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema>
</types>
<portType name="interfacelisPortType">
<operation name="checkin" >
<input message="tns:checkinRequest"/>
<output message="tns:checkinResponse"/>
</operation>
</portType>
<binding name="interfacelisBinding" type="tns:interfacelisPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="checkin">
<soap:operation soapAction="urn:interfacelis#checkin"/>
<input>
<soap:body use="literal" namespace="urn:interfacelis" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="literal" namespace="urn:interfacelis" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" parts="return"/>
</output>
</operation>
</binding>
<service name="interfacelis">
<port name="interfacelisPort" binding="tns:interfacelisBinding">
<soap:address location="urn:interfaceliswebservice"/>
</port>
</service>
<message name="checkinRequest">
<part name="json_array" type="xsd:string"/>
</message>
<message name="checkinResponse">
<part name="return" type="xsd:string"/>
</message>
</definitions>
JAX-WS - самогенерируемый WSDL, который работает на POSTMAN, но не на PHP:
<?xml version='1.0' encoding='UTF-8'?>
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-. -->
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-. -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsp="http://www.w3.org/ns/ws-policy"
xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://wsdlminsal/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://wsdlminsal/" name="wsminsal">
<types>
<xsd:schema>
<xsd:import namespace="http://wsdlminsal/" schemaLocation="http://localhost:8084/MinsalService/wsminsal?xsd=1" />
</xsd:schema>
</types>
<message name="checkin">
<part name="parameters" element="tns:checkin" />
</message>
<message name="checkinResponse">
<part name="parameters" element="tns:checkinResponse" />
</message>
<portType name="wsminsal">
<operation name="checkin">
<input wsam:Action="http://wsdlminsal/wsminsal/checkinRequest" message="tns:checkin" />
<output wsam:Action="http://wsdlminsal/wsminsal/checkinResponse" message="tns:checkinResponse" />
</operation>
</portType>
<binding name="wsminsalPortBinding" type="tns:wsminsal">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<operation name="checkin">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="wsminsal">
<port name="wsminsalPort" binding="tns:wsminsalPortBinding">
<soap:address location="http://localhost:8084/MinsalService/wsminsal" />
</port>
</service>
</definitions>