gpt4 book ai didi

java - 从 PHP 调用 Web 服务

转载 作者:行者123 更新时间:2023-12-02 08:05:04 25 4
gpt4 key购买 nike

我一直在尝试从下到上的方法调用在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"));

我的网络服务在使用 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 已经在我的 php 中启用了soap 扩展。

最佳答案

您可以使用的一个不错的工具是 wsdl2php-interpreter ,它将为您创建四个类等。

关于java - 从 PHP 调用 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8312440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com