前读:android链接本机的IIS需要用IPV4地址访问,其他地址访问可能访问不了

1、先用VS2008建立一个webservice,提供的方法如下

[WebService(Namespace="http://tempuri.org/")]

[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]

[ToolboxItem(false)]


[SoapDocumentService(RoutingStyle=SoapServiceRoutingStyle.RequestElement)]

publicclassService1:System.Web.Services.WebService

{

[WebMethod]

publicArrayListgetStr()

{

ArrayLista=newArrayList();

a.Add("haha");

a.Add("bb");

a.Add("cc");

returna;

}

}

2、调用结果如下

Web.configSystem.web节点内加上如下子节点,防止发布到IIS后无法在网页中调用

出现以上错误需要添加如下节点,但是我们在android端调用的话不用配置此节点

<webServices>

<protocols>

<!--<addname="HttpGet"/>-->

<addname="HttpGet"/>

</protocols>

</webServices>

3、Android端的activity的核心代码如下(先添加如下提供的第三方库)


代码截图:


原文:

Stringnamespace="http://tempuri.org/";

StringmethoName="getStr";

SoapObjectsoapObject=newSoapObject(namespace,methoName);

SoapSerializationEnvelopeenvelope=newSoapSerializationEnvelope(SoapEnvelope.VER11);

envelope.dotNet=true;

envelope.setOutputSoapObject(soapObject);//envelope.bodyOut=request;

//或者AndroidHttpTransporthttpTranstation=newAndroidHttpTransport("http://192.168.172.82/Service1.asmx?wsdl");

HttpTransportSEhttpTranstation=newHttpTransportSE("http://192.168.172.82/Service1.asmx?wsdl");//红色部分可要可不要

try{

httpTranstation.call(namespace+methoName,envelope);

SoapObjectresult=(SoapObject)envelope.getResponse();

//

如果返回webservice返回类型不是数组类型,则上面这句话改成

Objectresult=envelope.getResponse();并且取Value即可

intcount=result.getPropertyCount();

for(intindex=0;index<count;index++){

strList.add(result.getProperty(index).toString());

}

adapter=newArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,strList);

provinceListView.setAdapter(adapter);

更多相关文章

  1. AndRoid完全退出程序
  2. [Innost]Android深入浅出之Binder机制
  3. Android发送短信方法实例详解
  4. Android中ListView中Item的设置
  5. 利用Handler来更新android的UI
  6. android 包管理系统分析
  7. Android下打印调用栈
  8. Java工程中调用Android库出现“Stub!”错误
  9. 如何去除launcher 上默认的 google search bar.

随机推荐

  1. 在SQL Server中使用SQL语句查询一个存储
  2. sql不常用函数总结以及事务,增加,删除触发
  3. sqlserver中将varchar类型转换为int型再
  4. SQL语句删除2条重复数据一条保留一条
  5. 将Reporting services的RDL文件拷贝到另
  6. sqlserver 修改列名及表名的sql语句
  7. SQL Server 作业同步 (结合备份作业)
  8. SQLServer中用T—SQL命令查询一个数据库
  9. SQL Server 作业的备份(备份作业非备份数
  10. SQL Server 复制需要有实际的服务器名称