簡體   English   中英

WCF KSOAP的自托管服務(android)

[英]WCF Self hosted service for KSOAP(android)

我已經有適用於Android的應用了。 到目前為止,我一直在通過Web服務(標准asmx文件)使用KSOAP通信。 一切正常,但是一個月來,我一直在嘗試使用自托管的WCF服務為我的應用程序傳遞數據。

我已經使用WCF的配置進行了所有組合,但是仍然出了問題。

大家好,我需要一個簡單的示例項目,如用於KSOAP的HelloWorld WCF服務。具有配置的端點,空間等。我將不勝感激。

我已經花了很多時間在網上搜索,但是無法根據所找到的信息來構建可運行的服務。

這是我第一次要尋求幫助...波蘭的最好問候

我遇到了同樣的問題,並以這種方式解決了(WCF綁定必須是basicHttpBinding,否則它將不起作用):

private static final String NAMESPACE = "http://tempuri.org/";
private static String URL="your url";

private static final String SOAP_ACTION_VALIDATION = "IValidateUser_wcf/ValidateUser";
private static final String VALIDATION_METHOD = "ValidateUser";

public boolean validateUser_WCF(String username, String password){

    SoapSerializationEnvelope envelope = null;
    SoapObject request = null;
    HttpTransportSE httpTransportSE = null;

    try {
        request = new SoapObject(NAMESPACE, VALIDATION_METHOD);
        request.addProperty("username", username);
        request.addProperty("password", password);

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

        //////////////////////////////                               
        // here you can add a HEADER element if you want
        Element[] header = new Element[1];  

        header[0] = new Element().createElement(NAMESPACE_INFOCAD, "a1");                
        header[0].addChild(Node.TEXT, "HeaderTextContent");

        envelope.headerOut = header;
        //////////////////////////////                               

        // second parameter is timeout:
        httpTransportSE = 
            new HttpTransportSE(URL+VALIDATION_URI, 10*10000); 
        httpTransportSE.debug = true;
        httpTransportSE.setXmlVersionTag(
           "<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        httpTransportSE.call(NAMESPACE+SOAP_ACTION_VALIDATION, envelope);

        // if response is a simple text result, you can call
        // SoapPrimitive, if not, you have to call SoapObject 
        // result and navigate in response's tree like an xml file
        SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

        //To get the data.
        String textResult = result.toString();
        Log.i("textResult", textResult); 

        return true;

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }finally{
       // here you can see in LOG what is request you send and what is response received
        Log.i(getClass().getSimpleName(),"requestDump : "+httpTransportSE.requestDump);
        Log.i(getClass().getSimpleName(),"responseDump : "+httpTransportSE.responseDump);
    }

    return false;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM