【发布时间】:2011-11-29 14:29:16
【问题描述】:
我一直在尝试从下到上调用在 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"));
我的 web 服务在使用 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编写的webservice。
我想提一下,我正在使用 php 5 并且 wamp 已经在我的 php 中启用了soap扩展。
【问题讨论】:
-
您可以使用 file_get_contents($url) 将 WSDL 加载到 PHP 中吗?是 PHP 配置设置不允许它访问吗?
-
是的,我可以从 file_get_contents 加载它,甚至还可以在 ie 中看到它。
-
经过这么长时间的努力,我遇到了这个错误:....信息:发生故障! org.codehaus.xfire.fault.XFireFault:没有为操作接收到足够的消息部分。
标签: java php web-services wsdl soap-client