gpt4 book ai didi

android - 在 Android 中调用 .NET Web 服务时没有任何反应

转载 作者:行者123 更新时间:2023-11-30 04:04:46 25 4
gpt4 key购买 nike

我在 .net 中开发了一个 web 服务,就在这里

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class DataManipulationService : System.Web.Services.WebService
{
[WebMethod]
public void InsertData()
{
SQLConnectionManager conn = new SQLConnectionManager();

string qry = "INSERT INTO TEST_TABLE(Id, Name) VALUES(3, 'Ibbi')";

SQLOperationManager op = new SQLOperationManager(qry);
int rowsAffected = op.ExecuteQuery();
}
}

我正在尝试从 android 中调用这个 web 方法,就像这样

public class WebDataManipulator {

private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://localhost/DataManipulationService.asmx?WSDL";
private final String METHOD = "InsertData";
private final String SOAP_ACTION = "http://localhost/DataManipulationService.asmx?op=InsertData";

public void insertData() {
SoapObject request = new SoapObject(NAMESPACE, METHOD);

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

System.out.println(request);
HttpTransportSE androidHttp = new HttpTransportSE(URL);


try {
androidHttp.call(SOAP_ACTION, envelope);
} catch(Exception ex) {
ex.printStackTrace();
}
}

我已经在 .net 中测试了我的 Web 服务并且它工作正常但是当我在 android 上运行它时没有发生任何事情.. 我没有得到任何异常也没有它的功能。为什么?这是我的日志

08-11 11:09:12.269: I/AndroidRuntime(325): NOTE: attach of thread 'Binder Thread #3' failed
08-11 11:09:13.179: I/System.out(333): InsertData{}
08-11 11:09:13.229: W/System.err(333): java.net.SocketException: Permission denied
08-11 11:09:13.239: W/System.err(333): at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method)
08-11 11:09:13.239: W/System.err(333): at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(BlockGuard.java:335)
08-11 11:09:13.239: W/System.err(333): at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:216)
08-11 11:09:13.249: W/System.err(333): at java.net.Socket.checkOpenAndCreate(Socket.java:802)
08-11 11:09:13.249: W/System.err(333): at java.net.Socket.connect(Socket.java:948)
08-11 11:09:13.249: W/System.err(333): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
08-11 11:09:13.249: W/System.err(333): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
08-11 11:09:13.249: W/System.err(333): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
08-11 11:09:13.249: W/System.err(333): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
08-11 11:09:13.249: W/System.err(333): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
08-11 11:09:13.249: W/System.err(333): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
08-11 11:09:13.249: W/System.err(333): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
08-11 11:09:13.249: W/System.err(333): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
08-11 11:09:13.249: W/System.err(333): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:146)
08-11 11:09:13.249: W/System.err(333): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
08-11 11:09:13.249: W/System.err(333): at com.automated.research.WebDataManipulator.insertData(WebDataManipulator.java:27)
08-11 11:09:13.259: W/System.err(333): at com.automated.research.DataSender$1.run(DataSender.java:47)
08-11 11:09:13.259: I/System.out(333): connected

这就是我编写客户端代码的方式

if(isNetworkAvailable()) {
WebDataManipulator webDM = new WebDataManipulator();
webDM.insertData();
System.out.println("connected");
}

最佳答案

webserviceurl 以“localhost”开头,从 android 的角度来看是 android 设备。将 localhost 替换为 android 设备可以看到的 ip 地址(即可以从 android 网络浏览器调用)

关于android - 在 Android 中调用 .NET Web 服务时没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11911012/

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