2011-09-26 62 views
0

我试图从Web服务获取响应。但是我得到了一些异常错误:主要是这一个android:ksoap2 org.xmlpull.v1.XmlPullParserException:预期:START_TAG例外

org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@1:6 in [email protected]) 

其实我试图访问一个Web服务的方法和web服务应该返回两个字符串(比方说,字符串1和字符串)。此外,我必须提供或传递两个参数(可以说参数1和参数2,将参数1应该是整数,参数2应该是字符串)这里是我的代码

public class MyWebService extends Activity { 

private static final String SOAP_ACTION ="http://www.mywebsite.com/myMethod"; 
private static final String METHOD_NAME = "MyMethod"; 
private static final String NAMESPACE = "http://www.myNamespace/"; 
    private static final String URL = "http://mysession.com/myservice.asmx?WSDL"; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    try { 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

     PropertyInfo pi = new PropertyInfo(); 
     pi.setName("Parameter 1"); 
     pi.setValue(1); 
     pi.setType(pi.INTEGER_CLASS); 
     request.addProperty(pi); 

     PropertyInfo pi2 = new PropertyInfo(); 
     pi2.setName("Parameter 2"); 
     pi2.setValue("Any string"); 
     pi2.setType(pi2.STRING_CLASS); 
     request.addProperty(pi2); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.dotNet=true; 
     envelope.setOutputSoapObject(request); 

     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
     androidHttpTransport.call(SOAP_ACTION, envelope);     
     //SoapObject result=(SoapObject)envelope.getResponse();    
     SoapPrimitive result = (SoapPrimitive) envelope.getResponse(); 
     String resultData = result.toString(); 

     //String string1=result.getProperty(0).toString(); 
     //String string2=result.getProperty(1).toString(); 

     Log.v("WEBSERVICE","RESPONSE: "+resultData); 
    } catch (Exception e) { 
     e.printStackTrace();  

    }   
} 

}

谁能告诉我如果我在这里做错了什么..另一个非常重要的问题: 任何人都可以告诉我,为什么我不能在这里使用getProperty(0)或getProperty(1)方法。我应该得到来自web服务响应两个字符串,但我不能SoapPrimitive使用的getProperty(指数).. 所有的建议表示赞赏 感谢

+1

首先将你的网址改为'http://mysession.com/myservice.asmx'.After检查你的'SOAP_ACTION','METHOD_NAME'和'NAMESPACE'是否正确,通常是'SOAP_ACTION = NAMESPACE + METHOD_NAME'。 –

回答

0

我不知道这是精确解你所需要的,但这个作品对于我来说,我之前遇到过同样的问题,但是有5个参数需要使用,我只是使用SoapObject添加了3个参数,所以它给出了这种类型的错误,所以请确保您已经使用request.addProperty添加了所有需要的参数(“测试”,“测试”)在调用此webservice之前。

相关问题