我在访问用 PHP 制作的 Web 服务时遇到问题。我尝试了很多代码,但不知道我是否有一个愚蠢的错误让我无法工作。
我认为 Web 服务很好,因为如果我从 PHP 中的页面进行调用,但如果我通过 Android 访问不起作用,那么我在 ANDROID 中进行的调用也是如此。
错误发生在:transporte.call(SOAP_ACTION,envelope,null);
错误是:org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://www.w3.org/2003/05/soap-envelope}Envelope (position:START_TAG <definitions name='SMB_GestionBoda' targetNamespace='http://localhost/webservice/SMB_GestionBoda.wdsl'>@8:43 in java.io.InputStreamReader@405d9f50)
谢谢。
WSDL:
<definitions
name='SMB_GestionBoda'
targetNamespace='http://localhost/webservice/SMB_GestionBoda.wdsl'
xmlns:tns='http://localhost/webservice/SMB_GestionBoda.wdsl'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:soap12='http://schemas.xmlsoap.org/wsdl/soap12/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<message name='GetProvidersRequest'>
<part name='id_task' type='xsd:int'/>
<part name='city' type='xsd:string'/>
</message>
<message name='GetProvidersResponse'>
<part name='result'/>
</message>
<portType name='SMB_GestionBodaPortType'>
<operation name='GetProviders'>
<input message='tns:GetProvidersRequest'/>
<output message='tns:GetProvidersResponse'/>
</operation>
</portType>
<binding name='SMB_GestionBodaBinding' type='tns:SMB_GestionBodaPortType'>
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='GetProviders'>
<soap:operation soapAction='urn:localhost-SMB_GestionBoda#GetProviders'/>
<input>
<soap:body use='encoded' namespace='urn:localhost-SMB_GestionBoda'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace='urn:localhost-SMB_GestionBoda'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<service name='SMB_GestionBodaService'>
<port name='SMB_GestionBodaPort' binding='SMB_GestionBodaBinding'>
<soap:address location='http://localhost/webservice/GetProviders.php'/>
</port>
</service>
</definitions>
安卓代码:
//Constantes para la invocacion del web service
final String NAMESPACE = "http://localhost/webservice/SMB_GestionBoda.wdsl";
final String URL="http://192.168.0.10/webservice/SMB_GestionBoda.wdsl";
final String METHOD_NAME = "GetProviders";
final String SOAP_ACTION = "urn:localhost-SMB_GestionBoda#GetProviders";
/*Se crea un objeto SoapObject para poder realizar la peticion
para consumir el ws SOAP. El constructor recibe
el namespace. Por lo regular el namespace es el dominio
donde se encuentra el web service*/
request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("id_task",0);
request.addProperty("city","valencia");
/*Se crea un objeto SoapSerializationEnvelope para serealizar la
peticion SOAP y permitir viajar el mensaje por la nube
el constructor recibe la version de SOAP*/
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet = false; //se asigna true para el caso de que el WS sea de dotNet
//Se envuelve la peticion soap
envelope.setOutputSoapObject(request);
//Objeto que representa el modelo de transporte
//Recibe la URL del ws
HttpTransportSE transporte = new HttpTransportSE(URL);
transporte.debug=true;
try {
System.setProperty("http.keepAlive", "false");
//Hace la llamada al ws
transporte.call(SOAP_ACTION, envelope,null);
//Se crea un objeto SoapPrimitive y se obtiene la respuesta
//de la peticion
resultsRequestSOAP = (SoapPrimitive)envelope.getResponse();
//result = (SoapObject)envelope.bodyIn;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
Log.d("MI APP","dump : " + transporte.responseDump);
e.printStackTrace();
}
请求转储:
<v:Envelope
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://www.w3.org/2003/05/soap-encoding"
xmlns:v="http://www.w3.org/2003/05/soap-envelope">
<v:Header />
<v:Body>
<n0:GetProviders id="o0" c:root="1" xmlns:n0="http://localhost/webservice/SMB_GestionBoda.wdsl">
<id_task i:type="d:int">0</id_task>
<city i:type="d:string">valencia</city>
</n0:GetProviders>
</v:Body>
</v:Envelope>
响应转储:
<?xml version="1.0" encoding="utf-8"?>
<definitions
name='SMB_GestionBoda'
targetNamespace='http://localhost/webservice/SMB_GestionBoda.wdsl'
xmlns:tns='http://localhost/webservice/SMB_GestionBoda.wdsl'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:soap12='http://schemas.xmlsoap.org/wsdl/soap12/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<message name='GetProvidersRequest'>
<part name='id_task' type='xsd:int'/>
<part name='city' type='xsd:string'/>
</message>
<message name='GetProvidersResponse'>
<part name='result'/>
</message>
<portType name='SMB_GestionBodaPortType'>
<operation name='GetProviders'>
<input message='tns:GetProvidersRequest'/>
<output message='tns:GetProvidersResponse'/>
</operation>
</portType>
<binding name='SMB_GestionBodaBinding' type='tns:SMB_GestionBodaPortType'>
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='GetProviders'>
<soap:operation soapAction='urn:localhost-SMB_GestionBoda#GetProviders'/>
<input>
<soap:body use='encoded' namespace='urn:localhost-SMB_GestionBoda'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace='urn:localhost-SMB_GestionBoda'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<service name='SMB_GestionBodaService'>
<port name='SMB_GestionBodaPort' binding='SMB_GestionBodaBinding'>
<soap:address location='http://localhost/webservice/GetProviders.php'/>
</port>
</service>
</definitions>