title: ksoap2 consuming .Net service with sessions
body: <p>GetMessages is a method I have in a .net web service for my chat program. It gets a collection of messages, only sending new ones by saving the last message ID in a session variable.</p>
  
  <pre><code>HeaderProperty mSessionHeader = null;
  
  public SoapObject GetMessages()
  {
      ...
      SoapObject request = new SoapObject(NAMESPACE, METHOD);
  
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.V11);
      envelope.dotNet = true;
      envelope.bodyOut = request;
  
      HttpTransport transport = new HttpTransport(URL);
      transport.debug = true;
  
      // Build request header
      LinkedList&lt;HeaderProperties&gt; reqHeaders = new LinkList&lt;HeaderProperties&gt;();
  
      if (mSessionHeader != null) {
          reqHeaders.add(mSessionHeader); //using the session id from last header
      }
  
      List&lt;HeaderProperties&gt; respHeaders = transport.call(ACTION, envelope, reqHeaders);
  
      // See note after code
      for (HeaderProperty hp : respHeaders) {
          if (hp.getKey().equalsIgnoreCase("set-cookie"))
          {
              mSessionHeader = hp;
              break;
          }
      }
  
      return (SoapObject) envelope.getResponse();
  }
  </code></pre>
  
  <p>the value of mSessionHeader is something like </p>
  
  <blockquote>
    <p>set-cookie: ASP.NET_SessionId=0zzfwxxp1sakeafybjzsxp0k; path=/; HttpOnly</p>
  </blockquote>
  
  <p>However, the GUID part changes every call to ... transport.call()<br>
  When I use the same header (by putting if mSessionHeader == null around the for loop)
  it still does not work... the method gets every message sent regardless of the
  position i set in the Web Service</p>
  
  <p>Do I have to add more headers then just the ASP.NET_SessionId?</p>