从Android应用程序访问php Web服务

时间:2012-07-12 09:29:26

标签: php android web-services ksoap2

我尝试从我的Android应用程序访问php webservice。但它会出现此错误“”预期:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope(职位:START_TAG @ 11.43)在java中io.inputStreamReader@4052d300)“。这是我的wsdl文件

 <?xml version ='1.0' encoding ='UTF-8' ?>

<definitions 
name='product' 
targetNamespace='urn:PHP_SOAP_RPC' 
xmlns:tns='urn:PHP_SOAP_RPC' 
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' 
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' 
xmlns='http://schemas.xmlsoap.org/wsdl/'>  

 <message name='gettestRequest'>
<part name='id' type='xsd:string'/>
</message>
<message name='gettestRespones'>
<part name='id' type='xsd:string'/>
</message>

<portType name='productPortType'>               
    <operation name='gettest'> 
    <input message='tns:gettestRequest'/> 
    <output message='tns:gettestRespones'/> 
    </operation>         
</portType>
 <binding name='productBinding' type='tns:productPortType'> 


    <soap:binding style='rpc' 
    transport='http://schemas.xmlsoap.org/soap/http'/>      

    <operation name='gettest'> 
        <soap:operation soapAction='urn:xmethods-delayed-quotes#gettest'/> 
        <input> 
        <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
        </input> 
        <output> 
        <soap:body use='encoded' namespace='urn:xmethods-delayed-quotes' 
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
        </output> 
    </operation>    
</binding>

<service name='product'> 
    <port name='productPortType' binding='productBinding'> 
    <soap:address location='http://111.223.189.236/webservice/server1.php'/> 
    </port> 
</service> 

和我的java文件

    String METHOD_NAME = "gettest";
    String NAME_SPACE = "urn:PHP_SOAP_RPC";
    String SOAP_ACTION = NAME_SPACE + METHOD_NAME;
    String URL = "http://111.223.189.236/webservice/shoppingcart.wsdl";


    SoapObject Request = new SoapObject(NAME_SPACE, METHOD_NAME);

    Request.addProperty("userId", "userId");


    SoapSerializationEnvelope soapEnvelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    // soapEnvelop.dotNet = true;
    soapEnvelop.setOutputSoapObject(Request);
    HttpTransportSE aht = new HttpTransportSE(URL);

    try {
        aht.call(SOAP_ACTION, soapEnvelop);
        SoapPrimitive resultString = (SoapPrimitive) soapEnvelop.getResponse();
        tv.setText(resultString.toString());

    } catch (Exception e) {
        tv.setText(e.toString());

}

这是我的php文件

<?php

echo "ccc";

 function gettest($id) {    
return $id;
  }
      $server1 = new SoapServer(null, array('uri'=> "urn://tyler/res"));
  $server1->addFunction("gettest"); 
  $server1->handle(); 

   ?>

1 个答案:

答案 0 :(得分:0)

更改您的网址和delete.wsdl然后再尝试 SoapPrimitive resultString =(SoapPrimitive)soapEnvelop.getResponse(); .not getresponse使用bodyin