【问题标题】:WCF Self hosted service for KSOAP(android)用于 KSOAP(android) 的 WCF 自托管服务
【发布时间】:2013-12-07 13:06:04
【问题描述】:

我已经有了我的安卓应用。到目前为止,我一直在使用带有 Web 服务的 KSOAP 通信 - 标准 asmx 文件。一切正常,但一个月来,我一直在尝试使用自托管的 WCF 服务为我的应用提供数据。

我已经使用 WCF 的配置进行了所有组合,但仍然出现问题。

伙计们,我需要一些简单的示例项目,例如用于 KSOAP 的 HelloWorld WCF 服务。配置端点、空间等。 我会很感激的。

我花了很多时间在网络上搜索,但我无法根据我找到的信息构建一个有效的服务。

这是我第一次寻求帮助... 来自波兰的问候

【问题讨论】:

    标签: c# android wcf web-services ksoap


    【解决方案1】:

    我遇到了同样的问题,用这种方法解决了(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;
    }
    

    【讨论】:

    • 感谢 Kinghomer 的回答。我的 ksoap 请求看起来很熟悉,我认为更大的问题在于我的 WCF 服务,您能与我分享这个 ksoap 示例的 C# WCF 项目吗?
    • 您使用的是哪个 ksoap 版本?和 WCF 绑定?
    • ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar
    • ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar 和 HttpBinding,但我在 WCF 中仍然做错了什么。就像我写的那样,我对 ksoap 和 asmx 没有问题 - 我现在有完美的工作数据库应用程序,但我不想使用 IIS 服务器,我正在尝试将 asmx 重写为自托管 WCF - 到目前为止没有成功:(
    • 我有3种不同的方式属性,哪一种是正确的? [WebInvoke(UriTemplate = "WelcomeUser", Method = "POST")] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle .Wrapped, ResponseFormat = WebMessageFormat.Xml)]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 2013-02-22
    相关资源
    最近更新 更多