PHP SoapClient calling Java Web-Service



这是我研究Web服务的第一天,我已经卡住了。

我得到了一个简单的Java代码:

@WebService
public class ProductCatalog {
    public void getCategory(String category) {
       System.out.println(category);
    }
}

然后我得到了PHP代码来调用这个函数:

try{
$client = new SoapClient("link/to/wsdl");
$category = "music";
$client->getCategory($category);
}
catch(SoapFault $exception){
    echo $exception->getMessage();  
}

控制台输出为空。

以下

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

使用相同的 PHP 代码工作,因此方法调用本身正在工作。

如前所述,这是我的第一天,所以请不要对我太苛刻!

编辑:这是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>

我遇到了同样的问题。像这样调用函数:

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

我不知道为什么,但是该函数的第一个参数是arg0,如果它不起作用,请使用可以连接到 Web 服务的程序检查 Web 服务,然后您将获得参数的名称。

最新更新