简体   繁体   English

PHP SoapClient调用Java Web服务

[英]PHP SoapClient calling Java Web-Service

this is first day I'm looking into Web-Services and I'm already stuck. 这是第一天,我正在研究Web服务,但已经陷入困境。

I got a simple Java-Code: 我得到了一个简单的Java代码:

@WebService
public class ProductCatalog {

    public void getCategory(String category) {
       System.out.println(category);
    }
}

Then I got the PHP-Code to call this function: 然后我得到了PHP代码来调用此函数:

try{
$client = new SoapClient("link/to/wsdl");

$category = "music";

$client->getCategory($category);
}
catch(SoapFault $exception){
    echo $exception->getMessage();  
}

The console output is null. 控制台输出为空。

The following 下列

public void getProducts() {
    System.out.println("Works");
}

with the same PHP-Code works, so the method call itself is working. 具有相同的PHP代码的作品,因此方法调用本身是有效的。

As said, it's my first day, so please don't go too hard on me! 如前所述,这是我的第一天,所以请不要对我太努力!

edit: here is the WSDL 编辑:这是WSDL

<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://main/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://main/" name="ProductCatalogService">
<types>
<xsd:schema>
<xsd:import namespace="http://main/" schemaLocation="http://127.0.0.1:8080/Testmart/ProductCatalogService?xsd=1"/>
</xsd:schema>
</types>
<message name="getProducts">
<part name="parameters" element="tns:getProducts"/>
</message>
<message name="getProductsResponse">
<part name="parameters" element="tns:getProductsResponse"/>
</message>
<portType name="ProductCatalog">
<operation name="getProducts">
<input wsam:Action="http://main/ProductCatalog/getProductsRequest" message="tns:getProducts"/>
<output wsam:Action="http://main/ProductCatalog/getProductsResponse" message="tns:getProductsResponse"/>
</operation>
</portType>
<binding name="ProductCatalogPortBinding" type="tns:ProductCatalog">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getProducts">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ProductCatalogService">
<port name="ProductCatalogPort" binding="tns:ProductCatalogPortBinding">
<soap:address location="http://127.0.0.1:8080/Testmart/ProductCatalogService"/>
</port>
</service>
</definitions>

I encountered the same problem. 我遇到了同样的问题。 Call the function like this: 像这样调用函数:

$response = $client->getCategory(array("arg0"=> $category));

I don't know why, but the first parameters of the function is arg0, if it's not working, check the webservice with programs that can connect to webservice, and than you'll get the name of params. 我不知道为什么,但是函数的第一个参数是arg0,如果它不起作用,请使用可以连接到webservice的程序检查webservice,然后您将获得params的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM