我编写此代码用于将 android 应用程序连接到服务器 ASP.NET 3.5,此代码适用于我的笔记本电脑,但是当我在我的手机中安装此应用程序时它不起作用
我认为我应该更改 IP 10.0.0.2 但是当我输入我的笔记本电脑 IP 时它也不起作用
public class MainActivity extends Activity {
public final String URL="http://10.0.0.2:42767/MathService/Service.asmx";
public final String METHOD_NAME="GetAllString";
public final String ACTION="http://tempuri.org/GetAllString";
public final String NAMESPACE="http://tempuri.org/";
public static String doo ="START";
public static String [] Result = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void CCC (View V) throws InterruptedException{
EditText getinput = (EditText) findViewById(R.id.editText1);
SoapObject Request = new SoapObject(NAMESPACE,METHOD_NAME);
PropertyInfo Pi = new PropertyInfo();
Pi.setName("str");
String ss= getinput.getText().toString();
Pi.setValue(ss);
Pi.setType(String.class);
Request.addProperty(Pi);
SoapSerializationEnvelope envolope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
envolope.dotNet = true;
envolope.setOutputSoapObject(Request);
son htpm = new son(URL,500000);
SoapObject response = null;
String [] ArrayOfString = null;
int number = 0;
try
{
htpm.call(ACTION,envolope);
response = (SoapObject) envolope.getResponse();
ArrayOfString = new String [response.getPropertyCount()];
for (int j=0;;j++)
{
number ++;
ArrayOfString[j] = response.getPropertyAsString(j);
if(ArrayOfString[j].equals("Finish"))
break;
}
//---link to Activity2---
Intent i = new Intent(this,ACT2.class);
i.putExtra("arg1",number-2);
for(int a=1;a<number-1;a++)
i.putExtra("str"+Integer.toString(a),ArrayOfString[a]);
startActivityForResult(i, number-1);
}
catch (Exception ex)
{
TextView textout = (TextView) findViewById(R.id.editText1);
textout.setText("error");
}
}
}