慕于我心 2017-01-08 06:16 采纳率: 50%
浏览 1081
已采纳

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>
  • 写回答

2条回答 默认 最新

  • 慕于我心 2017-01-08 11:46
    关注

    问题自己解决了,原因是利用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>
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的
  • ¥15 硬件IIC从模式的数据发送,中断数据的接收,不能用HAL库(按照时序图)
  • ¥20 QAxWidget上显示一个word文档后,如何直接在该QAxWidget上修改和保存word文档
  • ¥15 Simulink仿真报错,请问如何解决
  • ¥20 宝塔面板无法添加Node项目,一直处于正在添加脚本页面
  • ¥50 Dkeil5 CT107D单片机的程序编写
  • ¥30 Ubuntu20.04中PVN3D复现过程交叉编译问题
  • ¥60 不懂得怎么运行下载来的代码
  • ¥15 CST导出3D模型图为什么和软件显示不一样?