我无法通过asp.net从android

时间:2016-05-25 05:56:42

标签: android sql asp.net sql-server ksoap2

我在我的应用中使用了ksoap2库。

我的asp.net文件中有3个webmethod。 1方法是sql server查询,其余的是各种helloWorld,添加两个数字。

我在2012年检查了我的asp工作正常.3种方法效果很好。 问题是,当运行我的Android应用程序时,2种方法正常工作。 但是使用sql server的方法总是抛出错误:

  

05-25 13:35:46.630 8269-8478 / com.example.bruce.xmlwork W / System.err:   SoapFault - faultcode:' soap:Server' faultstring:'服务器无法使用   处理请求。 --->与网络相关或特定于实例的错误   在建立与SQL Server的连接时发生。服务器是   没找到或无法访问。验证实例名称是否为   正确并且SQL Server配置为允许远程连接。   (提供者:TCP提供者,错误:0 - 访问被拒绝。)--->访问是   否认' faultactor:' null'详情:org.kxml2.kdom.Node@241d2389 05-25   13:35:46.630 8269-8478 / com.example.bruce.xmlwork W / System.err:at   org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:137)   05-25 13:35:46.630 8269-8478 / com.example.bruce.xmlwork W / System.err:
  在org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)05-25   13:35:46.630 8269-8478 / com.example.bruce.xmlwork W / System.err:at   org.ksoap2.transport.Transport.parseResponse(Transport.java:129)05-25   13:35:46.630 8269-8478 / com.example.bruce.xmlwork W / System.err:at   org.ksoap2.transport.HttpTransportSE.parseResponse(HttpTransportSE.java:301)   05-25 13:35:46.630 8269-8478 / com.example.bruce.xmlwork W / System.err:
  在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:274)   05-25 13:35:46.660 8269-8478 / com.example.bruce.xmlwork W / System.err:
  在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)   05-25 13:35:46.660 8269-8478 / com.example.bruce.xmlwork W / System.err:
  在org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)   05-25 13:35:46.670 8269-8478 / com.example.bruce.xmlwork W / System.err:
  在   com.example.bruce.xmlwork.MainActivity.readData(MainActivity.java:156)   05-25 13:35:46.690 8269-8478 / com.example.bruce.xmlwork W / System.err:
  在   com.example.bruce.xmlwork.MainActivity $ MyAsyncTask.doInBackground(MainActivity.java:101)   05-25 13:35:46.690 8269-8478 / com.example.bruce.xmlwork W / System.err:
  在   com.example.bruce.xmlwork.MainActivity $ MyAsyncTask.doInBackground(MainActivity.java:89)   05-25 13:35:46.690 8269-8478 / com.example.bruce.xmlwork W / System.err:
  在android.os.AsyncTask $ 2.call(AsyncTask.java:288)05-25 13:35:46.690   8269-8478 / com.example.bruce.xmlwork W / System.err:at   java.util.concurrent.FutureTask.run(FutureTask.java:237)05-25   13:35:46.690 8269-8478 / com.example.bruce.xmlwork W / System.err:at   android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)05-25   13:35:46.690 8269-8478 / com.example.bruce.xmlwork W / System.err:at   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)   05-25 13:35:46.690 8269-8478 / com.example.bruce.xmlwork W / System.err:
  在   java.util.concurrent.ThreadPoolExecutor中$ Worker.run(ThreadPoolExecutor.java:587)

protected String readData(){
    Log.d("ddd","readData");
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    envelope.dotNet = true;

    HttpTransportSE ht = new HttpTransportSE(URL);
    try {
        ht.call(SOAP_ACTION, envelope);  //error occours
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        return response.toString();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return "no";
}

我怎么能解决这个问题..请帮助我。

---- -----加 在asp.net

    [WebMethod]
    public string returnName()
    {
        String strSql = "SELECT * from address";
        SqlConnection objCon = new SqlConnection();
        objCon.ConnectionString = "Data Source=192.168.13.79,1433;Initial Catalog=bruceBasic;User ID=sa;Password=***";
        objCon.Open();
        SqlCommand objCmd = new SqlCommand();
        objCmd.Connection = objCon;
        objCmd.CommandText = strSql;
        objCmd.CommandType = CommandType.Text;

        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = objCmd;
        DataSet tempDs = new DataSet("TEMP");
        adapter.Fill(tempDs);

        objCon.Close();


        return tempDs.Tables[0].Rows[0]["addr_city"].ToString();
    }

我允许在DB专业中进行远程连接。

0 个答案:

没有答案