如何使用从Android Web服务方法返回的GUID

时间:2014-07-01 08:54:49

标签: android session soap guid

我希望得到一个我正在解决的问题的答案。我有2个Web服务方法。第一个是登录webmethod,它返回一个SessionID,第二个是getExpenseTypes,它应返回一个费用数组,但告诉我SessionID无效。

我的登录请求

HttpPost post = new HttpPost(new URI(urlset.getUrl()));

                post.setHeader("SOAPAction", urlset.getAction());
                post.setHeader("Content-Type", urlset.getContentType());

                post.setEntity(new StringEntity(login.getSoapLogin(args[0].trim(),
                        args[1].trim())));


                HttpClient client = customHttpClient.getNewHttpClient();

                HttpResponse response = client.execute(post);
                statusCode = response.getStatusLine().getStatusCode();

                HttpEntity entity = response.getEntity();

                if (entity != null) {

                    instream = entity.getContent();
                    result = stringManipulator.convertStreamToString(instream);
                    sessionID = parseSessionId.parseSessionId(result);
                    instream.close();

                }

它返回

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><LoginResponse xmlns="http://tempuri.org/"><LoginResult>8e576dc05aa74c699640bb12094e0bde</LoginResult></LoginResponse></s:Body></s:Envelope>

我假设8e576dc05aa74c699640bb12094e0bde是SessionID,但后来我发现这是一个GUID。

所以第二个webmethod

HttpPost post = new HttpPost(new URI(urlset.getUrl()));
                post.setHeader("SOAPAction", "http://tempuri.org/IMobileService/GetExpenseTypes");
                post.setHeader("Content-Type", urlset.getContentType());
                Log.e("args[0]", args[0]);
                String sentity = getExpenseType.getExpenseTypeTest(args[0]
                        .trim());

                post.setEntity(new StringEntity(sentity));


                CustomHttpClient customHttpClient = new CustomHttpClient();
                HttpClient client = customHttpClient.getNewHttpClient();

                HttpResponse response = client.execute(post);
                statusCode = response.getStatusLine().getStatusCode();

                if (entity != null) {

                    instream = entity.getContent();
                    result = stringManipulator.convertStreamToString(instream);
                    instream.close();

                }

将存储的会话ID连接成StringEntity,如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetExpenseTypes>
         <!--Optional:-->
         <tem:sessionID>2b89eff0ebcf4fb8a11636256d94553e</tem:sessionID>
      </tem:GetExpenseTypes>
   </soapenv:Body>
</soapenv:Envelope>

然后它返回:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetExpenseTypesResponse xmlns="http://tempuri.org/"><GetExpenseTypesResult>ERR: Session 00000000000000000000000000000000 won't be found.</GetExpenseTypesResult></GetExpenseTypesResponse></s:Body></s:Envelope>

虽然我在期待:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <GetExpenseTypesResponse xmlns="http://tempuri.org/">
         <GetExpenseTypesResult>[{"Id":3,"ExpenseTypeName":"Accomodation","CustomerId":null},{"Id":4,"ExpenseTypeName":"Communication","CustomerId":null},{"Id":12,"ExpenseTypeName":"Entertainment","CustomerId":2},{"Id":1,"ExpenseTypeName":"Flight","CustomerId":null},{"Id":10,"ExpenseTypeName":"Fuel","CustomerId":2},{"Id":11,"ExpenseTypeName":"Meals","CustomerId":2},{"Id":2,"ExpenseTypeName":"Mileage","CustomerId":2},{"Id":13,"ExpenseTypeName":"Office Supplies","CustomerId":2},{"Id":6,"ExpenseTypeName":"Subsistence","CustomerId":null},{"Id":5,"ExpenseTypeName":"Transport","CustomerId":null}]</GetExpenseTypesResult>
      </GetExpenseTypesResponse>
   </s:Body>
</s:Envelope>

所以,我被告知这是因为SessionID是作为GUID发送的,但我之前从未使用过这些。我只是插入了一个看起来像字符串的会话ID。这显然是错误的。如何处理接收GUID而不是会话ID?

感谢。

0 个答案:

没有答案