我有一个java程序,它通过SOAP调用php(rpc)中的方法。 从几天开始,它不再适用于我现有的代码。 在我的开发机器上,我最近更新到php7.0,但在远程服务器上仍然运行php5.x.它既不适用于localhost,也不适用于远程服务器。两台机器都运行Ubuntu(开发16.04,远程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 UI中使用的示例soap调用:
<?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中单击validate时,它告诉我xml declration没有很好地形成。但我不知道如何改变它。
<?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>
答案 0 :(得分:0)
我在谷歌搜索后找到了解决方案。
问题是我在soap服务器类的顶部有一个include()声明,其中包含另一个php文件。另一个php文件在?>
结束标记后面有一个空行。我在最后一个支架后直接移动了结束标签,现在它可以工作了!