简体   繁体   English

WCF KSOAP的自托管服务(android)

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

I already have my app for android. 我已经有适用于Android的应用了。 So far I've been using KSOAP communication with a web service - standard asmx file. 到目前为止,我一直在通过Web服务(标准asmx文件)使用KSOAP通信。 Everything works just fine, but for a month I've been trying to use a self hosted WCF service to deliver data for my app. 一切正常,但是一个月来,我一直在尝试使用自托管的WCF服务为我的应用程序传递数据。

I did already all combinations with configurations of WCF but still something is going wrong. 我已经使用WCF的配置进行了所有组合,但是仍然出了问题。

Please guys, I need sample project of something as simple as a HelloWorld WCF service for KSOAP.With configured endpoints,space etc. I will really appreciate. 大家好,我需要一个简单的示例项目,如用于KSOAP的HelloWorld WCF服务。具有配置的端点,空间等。我将不胜感激。

I've spent a many hours searching the web, but I can't build a working service from the information I've found. 我已经花了很多时间在网上搜索,但是无法根据所找到的信息来构建可运行的服务。

This is first time that I have to ask for help... Best Regards from Poland 这是我第一次要寻求帮助...波兰的最好问候

I had same problem and solved in this way (WCF binding has to be basicHttpBinding, otherwise it doesn't work): 我遇到了同样的问题,并以这种方式解决了(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