【问题标题】:Problems getting Ksoap2 client to talk to PHP based webservice让 Ksoap2 客户端与基于 PHP 的 Web 服务通信时出现问题
【发布时间】:2012-07-18 17:30:23
【问题描述】:

我在获取 PC 和 Android 上的 ksoap2 客户端以正确与 PHP Web 服务通信时遇到问题。我已经尝试过 PHP 包含的库和 nusoap,但都不起作用。

忘记错误。 Android 和 PC 客户端都给出 org.xmlpull.v1.XmlPullParserException 但消息是不同的。例如 PC 给出 PI 不能以 xml 开头

这是我的 PC 客户端的代码。

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.*;

public class client {



    public static void main(java.lang.String args[]) {
        final String SOAP_ACTION = "http://secure.g4apps.com/submitAxios/writegpsdata";
        final String METHOD_NAME = "writegpsdata";
        final String NAMESPACE = "http://secure.g4apps.com/submitAxios/";
        final String URL = "http://secure.g4apps.com/submitAxios.php";

        SoapObject rpc = new SoapObject(NAMESPACE,METHOD_NAME);
        SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        rpc.addProperty("writegpsdataRequest","A1,E1,E1,AT333AT333,9055627513,2012-02-02 02:02:02,2012-02-02 02:02:02,-454545.343434,434343.232323,A334A334A334A443X,1000000,3434");


        env.bodyOut=rpc;
        env.encodingStyle = SoapSerializationEnvelope.XSD;

        HttpTransportSE ht = new HttpTransportSE(URL);
        ht.debug = true;

        try {
            ht.call(SOAP_ACTION, env);

            System.out.println(ht.requestDump);

        }
        catch(org.xmlpull.v1.XmlPullParserException ex2) {
            System.out.println("Error" + ex2.toString() );
        }
        catch (Exception ex){
            String error = ex.toString();
            System.out.println("Error: "+ error);
        }


    }
}

这是我的 PHP 服务器代码。这是函数 writegpsdata 工作的通信,但客户端在服务器响应时出错。

<?php
// submitGPS is a soap server which writes GPS data to a mysql database.
// requires the writegpsdata.inc file which contains the required function
// uses submitGPS.wsdl file for defining soap service

require_once ("writegpsdata.axios.inc.php");
//require_once ("lib/nusoap.php");

ini_set("soap.wsdl_cache_enabled","0"); //disabling WSDL caching
$server = new SoapServer("http://secure.g4apps.com/submitAxios.wsdl");
$server->AddFunction("writegpsdata");
$server->handle();
?>

为了更好的衡量,这里是 wsdl 文件。

<?xml version="1.0"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://secure.g4apps.com/submitAxios/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="submitAxios" targetNamespace="http://secure.g4apps.com/submitAxios/">
  <wsdl:message name="writegpsdataRequest">
    <wsdl:part name="writegpsdataRequest" type="xsd:string"/>
  </wsdl:message>
  <wsdl:message name="writegpsdataResponse">
    <wsdl:part name="writegpsdataResponse" type="xsd:string"/>
  </wsdl:message>
  <wsdl:portType name="submitAxios">
    <wsdl:operation name="writegpsdata">
      <wsdl:input message="tns:writegpsdataRequest"/>
      <wsdl:output message="tns:writegpsdataResponse"/>
    </wsdl:operation>
      </wsdl:portType>
  <wsdl:binding name="submitAxiosSOAP" type="tns:submitAxios">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="writegpsdata">
      <soap:operation soapAction="http://secure.g4apps.com/submitAxios/writegpsdata"/>
      <wsdl:input>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://secure.g4apps.com/submitAxios/" use="encoded"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://secure.g4apps.com/submitAxios/" use="encoded"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="submitAxios">
    <wsdl:port binding="tns:submitAxiosSOAP" name="submitAxiosSOAP">
      <soap:address location="http://secure.g4apps.com/submitAxios.php"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

【问题讨论】:

    标签: java php soap wsdl ksoap2


    【解决方案1】:

    事实证明,我的包含函数 writegpsdata 有一些额外的字符是或结尾(在 php 标记之外),我在 eclipse 中看不到。我复制了内容,删除了文件并将其粘贴到一个新文件中,离开时出现此错误。尽管我的 android 客户端仍然存在问题。稍后我可能会发布另一个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-04
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 2023-04-01
      • 2016-02-12
      相关资源
      最近更新 更多