如何在android中使用kso​​ap添加标题,用户名,密码sharepoint webservice

时间:2011-07-18 07:34:11

标签: android web-services sharepoint xmlpullparser

我正在编写一个Android应用程序,它将使用sharepoint 2010中lists.amx服务的getlistitems()方法。我正在使用kso​​ap2-android来处理我的soap消息。当我尝试进行身份验证时,我得到一个xmlpullparser异常,期望START_TAG ...为什么以下代码不会对sharepoint服务器进行身份验证?

private static final String SOAP_ACTION = "http://schemas.microsoft.com/sharepoint/soap/GetListItems";
private static final String METHOD_NAME = "GetListItems";
private static final String NAMESPACE = "http://schemas.microsoft.com/sharepoint/soap/";
private static final String URL = "http://www.domain.com/tr-TR/_vti_bin/Lists.asmx";

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

    TextView tv=(TextView)findViewById(R.id.tve);

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


    request.addProperty("listName", "Haberler");
    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);

// envelope.headerOut = new Element [1]; // envelope.headerOut [0] = buildAuthHeader();

    String authentication = android.util.Base64.encodeToString("myusername:mypassword".getBytes(), android.util.Base64.NO_WRAP);
    List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
    headers.add(new HeaderProperty("X-FORMS_BASED_AUTH_ACCEPTED","f" +authentication));

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;

    try {
        androidHttpTransport.call(SOAP_ACTION, envelope,headers);
        SoapObject response = (SoapObject) envelope.getResponse();

        tv.setText(response.toString());
        Log.e("SONUC",response.toString());

    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

2 个答案:

答案 0 :(得分:0)

不要发送空值。相反,添加所有值,然后尝试发送它。

答案 1 :(得分:0)

尝试使用NtlmTransport代替HttpTransportSE。 MayBe它适合你。