gpt4 book ai didi

.net - 如何从 android 调用 .NET Web 服务?

转载 作者:IT老高 更新时间:2023-10-28 22:09:24 25 4
gpt4 key购买 nike

我需要使用类似以下 URL 的 Web 服务:来自 android 的 "http://192.168.1.19/TestWeb/WebService.asmx"

请有人帮我举个完整的例子吗?

最佳答案

最后,我得到了我自己的问题的解决方案。

代码如下:

package projects.ksoap2sample;



import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.*;
import android.os.*;
import android.widget.TextView;

public class ksoap2sample extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";

private static final String METHOD_NAME = "HelloWorld";

private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.1.19/TestWeb/WebService.asmx";
TextView tv;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.text1);
call();

}

public void call()
{
try {

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("passonString", "Rajapandian");

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

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);

Object result = (Object)envelope.getResponse();

tv.setText(result.toString());
} catch (Exception e) {
tv.setText(e.getMessage());
}
}
}

关于.net - 如何从 android 调用 .NET Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1048310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com