Android:访问返回JSON的SOAP Webside

时间:2013-04-23 15:33:15

标签: android json soap webservices-client

我正在尝试使用SOAP连接到Webside并以JSON格式返回结果。但是我在这个问题上真的很黑,真的需要一些指导..

我的SoapAccess代码:

  public SoapAccess (){
        this.user_id = "MYID";
        this.password = "MYPASSWORD";
        this.busstop_id = "16010366";


    Thread networkThread = new Thread() {
    @Override
     public void run() {
          try {

    //Initialize soap request + add parameters
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        

    request.addProperty("user", user_id);
    request.addProperty("password",password);
    request.addPropertyIfValue("busStopId", busstop_id);

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

    // Make the soap call.
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        androidHttpTransport.call(SOAP_ACTION, envelope);     

        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
        Log.i("myapp",result.toString());
        System.out.println(" --- response ---- " + result); 
             }
             catch (Exception e) {
                 e.printStackTrace();
             }

            }
        };
    networkThread.start();
    }

SOAP如下所示:

    POST /InfoTransit/userservices.asmx HTTP/1.1
Host: 10.0.2.52
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://miz.it/infotransit/getUserRealTimeForecastByStop"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getUserRealTimeForecastByStop xmlns="http://miz.it/infotransit">
      <auth>
        <user>string</user>
        <password>string</password>
      </auth>
      <handShakeUser>
        <userIdentifier>string</userIdentifier>
        <token>string</token>
        <response>NONE or Success or GenericError or NotValidToken or NoExistingUser or WsAuthenticationError</response>
      </handShakeUser>
      <busStopId>string</busStopId>
    </getUserRealTimeForecastByStop>
  </soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getUserRealTimeForecastByStopResponse xmlns="http://miz.it/infotransit">
      <getUserRealTimeForecastByStopResult>string</getUserRealTimeForecastByStopResult>
    </getUserRealTimeForecastByStopResponse>
  </soap:Body>
</soap:Envelope>

LogCat中的系统错误:

04-23 17:31:50.819: W/System.err(11156): SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
04-23 17:31:50.819: W/System.err(11156):    at UserServices.isWsAuthenticatedPUB(WsAuthentication _wsAuth) in c:\DISK_E\SAE\Infotransit\App_Code\UserServices.cs:line 609
04-23 17:31:50.819: W/System.err(11156):    at UserServices.getUserRealTimeForecastByStop(WsAuthentication auth, HandShake handShakeUser, String busStopId) in c:\DISK_E\SAE\Infotransit\App_Code\UserServices.cs:line 460
04-23 17:31:50.819: W/System.err(11156):    --- End of inner exception stack trace ---' faultactor: 'null' detail: org.kxml2.kdom.Node@41b00dc0
04-23 17:31:50.819: W/System.err(11156):    at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:141)
04-23 17:31:50.823: W/System.err(11156):    at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
04-23 17:31:50.823: W/System.err(11156):    at org.ksoap2.transport.Transport.parseResponse(Transport.java:116)
04-23 17:31:50.823: W/System.err(11156):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:259)
04-23 17:31:50.823: W/System.err(11156):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
04-23 17:31:50.823: W/System.err(11156):    at com.mso.master.SoapAccess$1.run(SoapAccess.java:58)

有没有人可以给我一个关于如何连接到这个网站并得到一些结果的精确定位?

1 个答案:

答案 0 :(得分:0)

如果您只是想连接到网站并获取内容(JSON),我建议使用java httpconnection类。您可以获取文件内容的输入流。