0

我正在尝试使用 PHP 客户端使用 hello world AXIS2 SOAP Web 服务。Java 类是用 Netbeans 编写的,AXIS2 aar 文件是使用 Netbeans AXIS2 插件生成的。

你们以前都见过,但这里是 java 类:

public class SOAPHello {    
    public String sayHello(String username) {
        return "Hello, "+username;
    }  
}

AXIS2 生成的 wsdl 似乎包含了所有参数,因此当我使用该服务时,我必须使用如下疯狂的 PHP 脚本:

$client = new SoapClient("http://myhost:8080/axis2/services/SOAPHello?wsdl");
$parameters["username"] = "Dave";
$response = $client->sayHello($parameters)->return;
echo $response."!";

当我真正想做的只是

   echo $client->sayHello("Dave")."!";

我的问题有两个:为什么会这样?我能做些什么来阻止它?:)

以下是生成的 wsdl 的类型、消息和端口类型部分:

<wsdl:types>
   <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://soap.axis2.myhost.co.uk">
      <xs:element name="sayHello">
         <xs:complexType>
            <xs:sequence>
               <xs:element minOccurs="0" name="username" nillable="true" type="xs:string"/>
            </xs:sequence>
         </xs:complexType>
      </xs:element>
      <xs:element name="sayHelloResponse">
         <xs:complexType>
            <xs:sequence>
               <xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
            </xs:sequence>
         </xs:complexType>
      </xs:element>
   </xs:schema>
</wsdl:types>

<wsdl:message name="sayHelloRequest">
   <wsdl:part name="parameters" element="ns:sayHello"/>
</wsdl:message>    
<wsdl:message name="sayHelloResponse">
   <wsdl:part name="parameters" element="ns:sayHelloResponse"/>
</wsdl:message>

<wsdl:portType name="SOAPHelloPortType">
   <wsdl:operation name="sayHello">
      <wsdl:input message="ns:sayHelloRequest" wsaw:Action="urn:sayHello"/>
      <wsdl:output message="ns:sayHelloResponse" wsaw:Action="urn:sayHelloResponse"/>
   </wsdl:operation>
</wsdl:portType>
4

3 回答 3

1

我正在寻找同样的问题,但没有找到解决方案。似乎这是某种axis2哲学来生成这种我觉得非常不可读的蹩脚界面。但我认为,出于大多数目的,你会接受它。如果你不喜欢这样并且在你的应用程序中大量使用 web 服务,那么编写一个像这样的包装类:

class soapHelloWebservice {
   public function sayHello($username) {
      $client = new SoapClient("http://myhost:8080/axis2/services/SOAPHello?wsdl");
      $parameters["username"] = $username;
      return $client->sayHello($parameters)->return;
   } 
}
于 2010-02-08T00:44:31.527 回答
1

这称为文档/文字包装模式。请参阅此文档此文档。

基本上,当使用文档/文字请求编码时,客户端不一定发送它正在调用的 Web 服务操作的名称。服务器必须从请求对象中找出它。为了确保服务器可以做到这一点,为每个 Web 服务操作定义了不同的请求对象。

于 2012-03-01T20:27:46.933 回答
0

当使用 WSDL2JAVA 命令行工具(与 Axis2 捆绑在一起)生成客户端代码时,添加参数“ -uw ”以解包参数,即您无需在 bean 中设置参数,而是将它们作为方法参数发送。

我们在项目中一直使用它。

于 2014-11-24T10:17:14.570 回答