PHP:从 Java 调用 SOAP rpc webservice 时出错 - 之前工作过
PHP: Error calling SOAP rpc webservice from Java - Worked before
我有一个 java 程序,它通过 SOAP 调用 php (rpc) 中的方法。
几天后,它不再适用于我现有的代码。
在我的开发机器上,我最近更新到 php7.0,但在远程服务器上仍然有 php5.x 运行。它既不适用于本地主机,也不适用于远程服务器。两台机器都是 运行 Ubuntu (dev 16.04, remote 14.04)
我总是收到以下错误:
[SOAPException: faultCode=SOAP-ENV:Client; msg=Parsing error, response was:
The processing instruction target matching "[xX][mM][lL]" is not allowed.; targetException=org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6;
The processing instruction target matching "[xX][mM][lL]" is not allowed.]
我用 SOAP UI 测试过,它有效,没有错误。
我什至用 apache axis2 测试过,但也失败了。
问题是来自 php 脚本的响应似乎无效。
我查看了编码等,检查是否有新行或其他内容。但我不知道问题可能是什么。
在 Soap 中工作的示例 soap 调用 UI:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:searchQuery xmlns:ns1="http://localhost/Server.php" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<query xsi:type="xsd:string">oil</query>
</ns1:searchQuery>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
响应:当我在 Soap UI 中单击验证时,它告诉我 xml 声明格式不正确。但是我不知道怎么改。
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/Server.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><ns1:searchQueryResponse><return xsi:type="xsd:string">{
"prefixes": ..... }
</return></ns1:searchQueryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
我用来初始化 soap 服务器的 php 代码:
try {
ini_set ( "soap.wsdl_cache_enabled", "0" );
$server = new SOAPServer ( 'Server.wsdl' );
$server->setClass ( 'Webdienst' );
$server->handle ();
}
catch ( SOAPFault $f ) {
echo $f->getMessage ();
}
我的 wsdl 文件:
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/Server.php" 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:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Webdienst" targetNamespace="http://localhost/Server.php">
<types>
<xsd:schema targetNamespace="http://localhost/Server.php">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</xsd:schema>
</types>
<portType name="WebdienstPort">
<operation name="createRecord">
<documentation>Create a new record</documentation>
<input message="tns:createRecordIn"/>
<output message="tns:createRecordOut"/>
</operation>
<operation name="searchQuery">
<documentation>Search for the String</documentation>
<input message="tns:searchQueryIn"/>
<output message="tns:searchQueryOut"/>
</operation>
</portType>
<binding name="WebdienstBinding" type="tns:WebdienstPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="createRecord">
<soap:operation soapAction="http://localhost/Server.php#createRecord"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
</output>
</operation>
<operation name="searchQuery">
<soap:operation soapAction="http://localhost/Server.php#searchQuery"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
</output>
</operation>
</binding>
<service name="WebdienstService">
<port name="WebdienstPort" binding="tns:WebdienstBinding">
<soap:address location="http://localhost/Server.php"/>
</port>
</service>
<message name="createRecordIn">
<part name="recordURI" type="xsd:anyType"/>
<part name="documentURI" type="xsd:anyType"/>
<part name="content" type="xsd:anyType"/>
<part name="fileName" type="xsd:anyType"/>
<part name="mimeType" type="xsd:anyType"/>
<part name="creationDate" type="xsd:anyType"/>
<part name="datasetURI" type="xsd:anyType"/>
<part name="translatedContent" type="xsd:anyType"/>
<part name="alchemyTopics" type="xsd:anyType"/>
<part name="summary" type="xsd:anyType"/>
<part name="author" type="xsd:anyType"/>
</message>
<message name="createRecordOut">
<part name="return" type="xsd:string"/>
</message>
<message name="searchQueryIn">
<part name="query" type="xsd:anyType"/>
</message>
<message name="searchQueryOut">
<part name="return" type="xsd:string"/>
</message>
</definitions>
谷歌搜索后我找到了解决方案。
问题是我的 soap 服务器 class 顶部有一个 include() 声明,其中包含另一个 php 文件。另一个 php 文件在 ?>
结束标记后有一个空行。我在最后一个大括号之后直接移动了结束标记,现在可以使用了!
我有一个 java 程序,它通过 SOAP 调用 php (rpc) 中的方法。 几天后,它不再适用于我现有的代码。 在我的开发机器上,我最近更新到 php7.0,但在远程服务器上仍然有 php5.x 运行。它既不适用于本地主机,也不适用于远程服务器。两台机器都是 运行 Ubuntu (dev 16.04, remote 14.04)
我总是收到以下错误:
[SOAPException: faultCode=SOAP-ENV:Client; msg=Parsing error, response was:
The processing instruction target matching "[xX][mM][lL]" is not allowed.; targetException=org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6;
The processing instruction target matching "[xX][mM][lL]" is not allowed.]
我用 SOAP UI 测试过,它有效,没有错误。 我什至用 apache axis2 测试过,但也失败了。
问题是来自 php 脚本的响应似乎无效。
我查看了编码等,检查是否有新行或其他内容。但我不知道问题可能是什么。
在 Soap 中工作的示例 soap 调用 UI:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:searchQuery xmlns:ns1="http://localhost/Server.php" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<query xsi:type="xsd:string">oil</query>
</ns1:searchQuery>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
响应:当我在 Soap UI 中单击验证时,它告诉我 xml 声明格式不正确。但是我不知道怎么改。
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/Server.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><ns1:searchQueryResponse><return xsi:type="xsd:string">{
"prefixes": ..... }
</return></ns1:searchQueryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
我用来初始化 soap 服务器的 php 代码:
try {
ini_set ( "soap.wsdl_cache_enabled", "0" );
$server = new SOAPServer ( 'Server.wsdl' );
$server->setClass ( 'Webdienst' );
$server->handle ();
}
catch ( SOAPFault $f ) {
echo $f->getMessage ();
}
我的 wsdl 文件:
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/Server.php" 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:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Webdienst" targetNamespace="http://localhost/Server.php">
<types>
<xsd:schema targetNamespace="http://localhost/Server.php">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</xsd:schema>
</types>
<portType name="WebdienstPort">
<operation name="createRecord">
<documentation>Create a new record</documentation>
<input message="tns:createRecordIn"/>
<output message="tns:createRecordOut"/>
</operation>
<operation name="searchQuery">
<documentation>Search for the String</documentation>
<input message="tns:searchQueryIn"/>
<output message="tns:searchQueryOut"/>
</operation>
</portType>
<binding name="WebdienstBinding" type="tns:WebdienstPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="createRecord">
<soap:operation soapAction="http://localhost/Server.php#createRecord"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
</output>
</operation>
<operation name="searchQuery">
<soap:operation soapAction="http://localhost/Server.php#searchQuery"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/Server.php"/>
</output>
</operation>
</binding>
<service name="WebdienstService">
<port name="WebdienstPort" binding="tns:WebdienstBinding">
<soap:address location="http://localhost/Server.php"/>
</port>
</service>
<message name="createRecordIn">
<part name="recordURI" type="xsd:anyType"/>
<part name="documentURI" type="xsd:anyType"/>
<part name="content" type="xsd:anyType"/>
<part name="fileName" type="xsd:anyType"/>
<part name="mimeType" type="xsd:anyType"/>
<part name="creationDate" type="xsd:anyType"/>
<part name="datasetURI" type="xsd:anyType"/>
<part name="translatedContent" type="xsd:anyType"/>
<part name="alchemyTopics" type="xsd:anyType"/>
<part name="summary" type="xsd:anyType"/>
<part name="author" type="xsd:anyType"/>
</message>
<message name="createRecordOut">
<part name="return" type="xsd:string"/>
</message>
<message name="searchQueryIn">
<part name="query" type="xsd:anyType"/>
</message>
<message name="searchQueryOut">
<part name="return" type="xsd:string"/>
</message>
</definitions>
谷歌搜索后我找到了解决方案。
问题是我的 soap 服务器 class 顶部有一个 include() 声明,其中包含另一个 php 文件。另一个 php 文件在 ?>
结束标记后有一个空行。我在最后一个大括号之后直接移动了结束标记,现在可以使用了!