Search code examples
sharepointsoapksoap2

Soap sharepoint envelope


I try to construct a correct soap envelope used ksoap2 lib

...

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        request.addProperty("listName", "Tasks");
        request.addProperty("viewName", null);
        request.addProperty("query", null);
        request.addProperty("viewFields", null);
        request.addProperty("rowLimit", "30");
        request.addProperty("queryOptions", null);
        request.addProperty("webID",null);

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

        String authentication = android.util.Base64.encodeToString("Administrator:Password".getBytes(), android.util.Base64.NO_WRAP);
        List<HeaderProperty> headers = new ArrayList<HeaderProperty>();

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        androidHttpTransport.debug = true;

        try {
          headers.add(new HeaderProperty("Authorization", "Basic " + authentication));
          androidHttpTransport.call(SOAP_ACTION, envelope, headers);
            Log.d("D", androidHttpTransport.requestDump);
            SoapObject response = (SoapObject) envelope.getResponse();
...

In debug mode I see this envelope:

  <?xml version="1.0" encoding="utf-8"?>
    <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
       <v:Header/>
       <v:Body>
          <GetListItems id="o0" c:root="1" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
             <listName i:type="d:string">Tasks</listName>
             <viewName i:null="true"/>
             <query i:null="true"/>
             <viewFields i:null="true"/>
             <rowLimit i:type="d:string">30</rowLimit>
             <queryOptions i:null="true"/>
             <webID i:null="true"/>
          </GetListItems>
       </v:Body>
    </v:Envelope>

Where is header data? Maybe its will be add in the call method? Its a correct envelope? And I had the same mistakes from my previous post with authorization in server.


Solution

  • Header data is sent in HTTP headers, not in SOAP body, that is why they call it headers. When you use "HTTP basic" authentication, an Authorization header is added. See an example from Wikipedia: http://en.wikipedia.org/wiki/Basic_access_authentication#Example