PHP写了一个webservice接口,测试代码连接出问题。

错误如下:

 Exception in thread "main" org.codehaus.xfire.fault.XFireFault: Procedure 'innerID' not present
    at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
    at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
    at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
    at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
    at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
    at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
    at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
    at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
    at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
    at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
    at org.codehaus.xfire.client.Client.invoke(Client.java:336)
    at org.codehaus.xfire.client.Client.invoke(Client.java:368)
    at com.webservices.test.sysUserClientTest.main(sysUserClientTest.java:12)

接口php如下:
    <?php

class yqyy{
  public function apply($innerID,$insCode){
    $config = include('config.php');
    $baseUrl=$config['baseUrl'];
    $MysqlHost=$config['MysqlHost'];
    $MysqlUser=$config['MysqlUser'];
    $MysqlPass=$config['MysqlPass'];
    $MysqlDb=$config['MysqlDb'];

    if(empty($innerID)){
        return $baseUrl."/rwyq.php";
    }           //数据库名
    //创建连接
    $link = mysql_connect($MysqlHost,$MysqlUser,$MysqlPass) or die("connect failed" . mysql_error());

    mysql_query("SET NAMES UTF8");
    mysql_query("set character_set_client=utf8"); 
    mysql_query("set character_set_results=utf8");

    $db_selected = mysql_select_db($MysqlDb, $link);

    if (!$db_selected){
        $msg = "===选择数据库失败===";
    }

    //查询仪器信息表
    $query = mysql_query(("select A01,B01 from  apparatus_in where A02='".$innerID."' and Auditing='1'"),$link);
    //判断是否有查询结果
    if($query){
        while($row = mysql_fetch_array($query)){
            $baseUrl = $baseUrl."/rwyq_n3.php?yqid=".$row['A01']."&coid=".$row['B01'];
        }
    }else{
        return  $baseUrl."/rwyq.php";
    }

    return $baseUrl;
  }
}
$server = new SoapServer('yqyy.wsdl', array( 'soap_version'=>SOAP_1_2));
$server->setClass("yqyy");
$server->handle(); 
?>

java类测试代码如下:

 public class sysUserClientTest {
    public static void main(String[] args) throws MalformedURLException, Exception {
        Client client = new Client(new URL("http://localhost/service/yqyy.php?wsdl"));
        Object[] results = client.invoke("apply", new Object[] {"123123","1234"});//innerID,insCode
        System.out.println(results[0].toString());
    }

PHP测试代码如下:

 $parmSoap = array('insCode' => $insCode , 'instruType' => 6);

ini_set('soap.wsdl_cache_enabled', "0");
$client = new SoapClient('http://localhost/service/yqyy.php?wsdl',array('cache_wsdl' => WSDL_CACHE_NONE));

$innerID = "1112594211985";
$insCode = "123";

$result = $client->apply($innerID,$insCode);
echo json_encode($result);

wsdl如下(使用zend studio生成的):

  <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost/service/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="yqyy" targetNamespace="http://localhost/service/">
<wsdl:types>
<xsd:schema targetNamespace="http://localhost/service/">
<xsd:element name="apply">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="in" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="applyResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="applyRequest">
<wsdl:part name="innerID" type="xsd:string"/>
<wsdl:part name="insCode" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="applyResponse">
<wsdl:part name="apply" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="yqyy">
<wsdl:operation name="apply">
<wsdl:input message="tns:applyRequest"/>
<wsdl:output message="tns:applyResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="yqyySOAP" type="tns:yqyy">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="apply">
<soap:operation soapAction="http://localhost/service/apply"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="yqyy">
<wsdl:port binding="tns:yqyySOAP" name="yqyySOAP">
<soap:address location="http://localhost/service/yqyy.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

问题自己解决了,原因是利用zend studio生成的wsdl是错误的,错误的地方及改动如下:

 <xsd:element name="apply">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="in" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

改为

 <xsd:element name="apply" type="xsd:string" ></xsd:element>

,,

 <wsdl:message name="applyRequest">
<wsdl:part name="innerID" type="xsd:string"/>
<wsdl:part name="insCode" type="xsd:string"/>
</wsdl:message>

改为

 <wsdl:message name="applyRequest">
    <wsdl:part element="tns:apply" name="innerID"/>
    <wsdl:part name="insCode" element="tns:apply"></wsdl:part>
  </wsdl:message>

修改之后的完整wsdl如下:

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost/service/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="yqyy" targetNamespace="http://localhost/service/">
  <wsdl:types>
    <xsd:schema targetNamespace="http://localhost/service/">
      <xsd:element name="apply" type="xsd:string" ></xsd:element>
      <xsd:element name="applyResponse">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="out" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="applyRequest">
    <wsdl:part element="tns:apply" name="innerID"/>
    <wsdl:part name="insCode" element="tns:apply"></wsdl:part>
  </wsdl:message>
  <wsdl:message name="applyResponse">
    <wsdl:part name="baseUrl" type="xsd:string"/>
  </wsdl:message>
  <wsdl:portType name="yqyy">
    <wsdl:operation name="apply">
      <wsdl:input message="tns:applyRequest"/>
      <wsdl:output message="tns:applyResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="yqyySOAP" type="tns:yqyy">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="apply">
      <soap:operation soapAction="http://localhost/service/apply"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="yqyy">
    <wsdl:port binding="tns:yqyySOAP" name="yqyySOAP">
      <soap:address location="http://localhost/service/yqyy.php?wsdl"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

补充wsdl内容

 <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost/service/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="yqyy" targetNamespace="http://localhost/service/">
<wsdl:types>
<xsd:schema targetNamespace="http://localhost/service/">
<xsd:element name="apply">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="in" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="applyResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="applyRequest">
<wsdl:part name="innerID" type="xsd:string"/>
<wsdl:part name="insCode" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="applyResponse">
<wsdl:part name="apply" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="yqyy">
<wsdl:operation name="apply">
<wsdl:input message="tns:applyRequest"/>
<wsdl:output message="tns:applyResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="yqyySOAP" type="tns:yqyy">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="apply">
<soap:operation soapAction="http://localhost/service/apply"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="yqyy">
<wsdl:port binding="tns:yqyySOAP" name="yqyySOAP">
<soap:address location="http://localhost/service/yqyy.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>