小编Bre*_*rad的帖子

在模拟器中使用kSOAP2使用localhost WCF服务

我已经把头撞在这堵墙上了几天,所以任何帮助都非常感激.

首先是一些背景知识.我是一位经验丰富的WindowsMo​​bile开发人员,因此我是Java,Android甚至WCF的老手.我已经做了很多关于如何使用kSOAP2在Android中使用WCF应用程序的研究,但无论我做得最好,我能想到的是Android中的套接字错误,因为超时.

首先,我在Visual Studio 2008中创建了一个Web服务应用程序,它不需要参数,只需使用字符串值进行响应.Web服务代码如下:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

namespace Sample
{
    [WebService(Namespace = "http://sample.com/")]
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public string SayHello()
        {
            return "Hello, Android. From your friend, WCF";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

对于此Web服务,我没有调整任何其他设置或对Web.config文件进行任何修改.

当我运行该服务时,它会打开我的浏览器并指向以下网址:

http://localhost:61554/Service1.asmx
Run Code Online (Sandbox Code Playgroud)

接下来,我跳入Eclipse并创建了一个简单的Android项目来使用WCF服务.对于初学者,我更改了AndroidManifest.xml文件并将此语句添加到其中:

<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud)

现在我的Android类的代码应该是繁重的工作:

package com.sample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import org.ksoap2.*;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.*;

public class Sample extends Activity {
    TextView result;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); …
Run Code Online (Sandbox Code Playgroud)

wcf android ksoap2

3
推荐指数
1
解决办法
8198
查看次数

标签 统计

android ×1

ksoap2 ×1

wcf ×1