用户名: 密码: 忘记密码? 注册
收藏此问题 发表新评论

php调用intellij idea写的webservice,参数死活搞不定,求破

本帖最后由 suck007 于 2013-6-18 16:47 编辑

如题~
intellij idea写的hello worldwebservicesoapUI测试通过但是php调用的话出问题下面是具体经过

java代码
**********************************************
package MyPackage;/**

public class HelloWorld {
  public String sayHelloWorldFrom(String p1)
  {
    String result = "Hello, world, from " + p1;
//    String result = "Hello, world";
    System.out.println(result);
    return result;
  }
}
**********************************************


wsdl地址是http://localhost:8080/MyPackage/services/HelloWorld?wsdl
内容是这个,idea里面根据java代码,自动生成的

<?xml version="1.0"encoding="UTF-8"?>
<wsdl:definitionstargetNamespace="http://MyPackage"xmlns:apachesoap="http://xml.apache.org/xml-soap"xmlns:impl="http://MyPackage" xmlns:intf="http://MyPackage"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version:1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:types>
<schema elementFormDefault="qualified"targetNamespace="http://MyPackage"xmlns="http://www.w3.org/2001/XMLSchema">
  <element name="p1" type="xsd:string"/>
  <element name="sayHelloWorldFromReturn"type="xsd:string"/>
</schema>
</wsdl:types>

  <wsdl:message name="sayHelloWorldFromResponse">

     <wsdl:part element="impl:sayHelloWorldFromReturn"name="sayHelloWorldFromReturn"/>

  </wsdl:message>

  <wsdl:message name="sayHelloWorldFromRequest">

     <wsdl:part element="impl:p1" name="p1"/>

  </wsdl:message>

  <wsdl:portType name="HelloWorld">

     <wsdl:operation name="sayHelloWorldFrom"parameterOrder="p1">

        <wsdl:input message="impl:sayHelloWorldFromRequest"name="sayHelloWorldFromRequest"/>

        <wsdl:output message="impl:sayHelloWorldFromResponse"name="sayHelloWorldFromResponse"/>

     </wsdl:operation>

  </wsdl:portType>

  <wsdl:binding name="HelloWorldSoapBinding"type="impl:HelloWorld">

     <wsdlsoap:binding style="document"transport="http://schemas.xmlsoap.org/soap/http"/>

     <wsdl:operation name="sayHelloWorldFrom">

        <wsdlsoap:operation soapAction="sayHelloWorldFrom"/>

        <wsdl:input name="sayHelloWorldFromRequest">

           <wsdlsoap:body use="literal"/>

        </wsdl:input>

        <wsdl:output name="sayHelloWorldFromResponse">

           <wsdlsoap:body use="literal"/>

        </wsdl:output>

     </wsdl:operation>

  </wsdl:binding>

  <wsdl:service name="HelloWorldService">

     <wsdl:port binding="impl:HelloWorldSoapBinding"name="HelloWorld">

        <wsdlsoap:addresslocation="http://localhost:8080/MyPackage/services/HelloWorld"/>

     </wsdl:port>

  </wsdl:service>

</wsdl:definitions>




php代码如下
<?php

   header("content-type:text/html;charset=utf-8");

   $soapUrl ="http://localhost:8080/MyPackage/services/HelloWorld?wsdl";

   $options = array( 'trace'=>true,
                     'cache_wsdl'=>WSDL_CACHE_NONE,
                      'soap_version'   => SOAP_1_1);

   $client = new SoapClient($soapUrl,$options);

   var_dump( $client->__getFunctions() );

   try
    {
       $params = 'fuckcms';

       $result = $client->sayHelloWorldFrom($params);


       var_dump($client->__getLastRequest());
       echo "<br>";

       var_dump($client->__getLastResponse());
       echo "<br>";

       var_dump($result);
       echo "<br>";

   }catch (SoapFault $exception)
    {
       var_dump($exception);
       echo "Request :<br>",htmlentities($client->__getLastRequest()), "<br>";
       echo "Response :<br>",htmlentities($client->__getLastResponse()), "<br>";
    }
?>


经过测试,javawebservice可以调用到,

但是php调用$result = $client->sayHelloWorldFrom($params);以后,$result为空值
如果javawebservice没有参数,php$result正常
如果javawebservice方法有两个,第二个参数,php无法传过去,用array之类的传过去,javawebservice显示p1参数均为array
php__soapCall等都用过,参数方式也试过很多次,搞不定,请大牛帮帮忙~

昵称: suck007  时间: 2013-06-18 16:42:25
哎,年轻人啊稍安勿躁,建议先把代码格式化下吧,看着头疼,DZ有格式化代码的功能
昵称: iminto  时间: 2013-06-18 18:40:13
PHP和Java等其他语言间的webService,我搞的多了,其实这货很简单,最最无奈的情况下,抓包就能解决一切。
参考我的博客:详解Webservice开发中遇到的问题和调试技巧
昵称: iminto  时间: 2013-06-18 18:43:50
发表评论
昵称:
内容:
验证: