我一直在尝试调用在java中创建的web服务从下到上的方法,并希望通过我的PHP文件调用它,但它总是给我一个错误。
我试过的代码:
$client = new SoapClient("http://localhost:8080/Indexer/services/IndexerService?wsdl");
$params = array(
'anId' => 3,
'action' => 'OMNOMNOMNOM',
'parameters' => array(
'Param' => array(
array('Name' => 'in0', 'Value' => 'Skinnarlyngen startar Välkommen')
)
));
$result = $client->__soapCall("getIds",$params);
print_r($result);
我尝试的第二段代码:
$wsdl = 'http://localhost:8080/Indexer/services/IndexerService?wsdl';
$client = new SoapClient($wsdl );
print($client->getIds("ibm"));
我的webservice是给完美的结果,而尝试与Java客户端:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://labs.aroha.com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" targetNamespace="http://labs.aroha.com">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://labs.aroha.com">
<xsd:element name="example">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="exampleResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="exampleRequest">
<wsdl:part name="parameters" element="tns:example"></wsdl:part>
</wsdl:message>
<wsdl:message name="exampleResponse">
<wsdl:part name="parameters" element="tns:exampleResponse"></wsdl:part>
</wsdl:message>
<wsdl:portType name="IndexerServicePortType">
<wsdl:operation name="example">
<wsdl:input name="exampleRequest" message="tns:exampleRequest"></wsdl:input>
<wsdl:output name="exampleResponse" message="tns:exampleResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="IndexerServiceHttpBinding" type="tns:IndexerServicePortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="example">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="exampleRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="exampleResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="IndexerService">
<wsdl:port name="IndexerServiceHttpPort" binding="tns:IndexerServiceHttpBinding">
<wsdlsoap:address location="http://localhost:8080/Indexer/services/IndexerService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
每次都给我以下错误:
Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost:8080/Indexer/services/IndexerService?wsdl' : failed to load external entity
有没有人可以帮助我,我如何在php代码调用java编写的web服务。
我想提一下,我使用php 5和wamp已经启用soap扩展在我的php.
你可以使用的一个很好的工具是wsdl2php-interpreter,它可以为你创建类等
使用以下代码
$Url = "http://localhost:8080/Indexer/services/IndexerService?wsdl";
$params = array ("param1" =>"value","parm2"=>"value");
$httpQuery = http_build_query ($params);
$contextData = array (
"method" => "POST",
"header" => "Connection: closern".
"Content-Length: ".strlen($httpQuery)."rn",
"content"=> $httpQuery );
$context = stream_context_create (array ( "http" => $contextData ));
$result = file_get_contents ($Url, false, $context);