当我尝试通过dotnet Web服务登录时,它会抛出此错误
03-15 17:15:28.899 29517-29959/com.example.welcom.abhinav
I/httpTransportSE: org.ksoap2.transport.HttpTransportSE@76bc3be 03-15
17:15:28.903 29517-29959/com.example.welcom.abhinav
D/NetworkSecurityConfig: No Network Security Config specified, using
platform default 03-15 17:15:29.050
29517-29959/com.example.welcom.abhinav I/messge: false
这是 xml 代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.welcom.abhinav.MainActivity">
<EditText
android:id="@+id/loc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Location"
android:inputType="textPersonName" />
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Email"
android:inputType="textPersonName" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/signin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign In" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:id="@+id/textView1"/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
这个类,我们可以从安卓应用程序点击网络服务
package com.example.welcom.abhinav;
import android.util.Log;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
/**
* Created by welcom on 15-03-2018.
*/
public class WebService {
private static String NAMESPACE="http://tempuri.org/";
private static String URL ="http://www.getcodify.in/webservice.asmx";
private static String SOAP_ACTION="http://tempuri.org/";
public static Boolean invokeHelloWorldWS(String user,String pass, String location, String webMethName)
{
Boolean loginStatus=false;
SoapObject request = new SoapObject(NAMESPACE, webMethName);
PropertyInfo userPI=new PropertyInfo();
PropertyInfo passPI=new PropertyInfo();
PropertyInfo locationPI=new PropertyInfo();
userPI.setName("user");
userPI.setValue(user);
userPI.setType(String.class);
Log.i("user",user);
passPI.setName("pass");
passPI.setValue(pass);
passPI.setType(String.class);
Log.i("pass",pass);
locationPI.setName("location");
locationPI.setValue(location);
locationPI.setType(String.class);
Log.i("location",location);
SoapSerializationEnvelope soapSerializationEnvelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapSerializationEnvelope.dotNet=true;
soapSerializationEnvelope.setOutputSoapObject(request);
HttpTransportSE httpTransportSE=new HttpTransportSE(URL);
Log.i("httpTransportSE",httpTransportSE.toString());
try{
httpTransportSE.call(SOAP_ACTION+webMethName,soapSerializationEnvelope);
SoapPrimitive response= (SoapPrimitive) soapSerializationEnvelope.getResponse();
loginStatus=Boolean.parseBoolean(response.toString());
Log.i("messge",loginStatus.toString());
}
catch (Exception e)
{
MainActivity.errored=true;
e.printStackTrace();
}
return loginStatus;
}
}
这是应用程序中应用程序的主要活动类,我们可以调用 Web 服务.class
package com.example.welcom.abhinav;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button logIn;
EditText location;
EditText emailEt;
EditText passEt;
TextView disLoc;
TextView disEm;
TextView disPass;
Boolean displayLocation;
String displayEmail;
String displayPassword;
String loc;
String em;
String pass;
static Boolean errored=false;
//ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
location=findViewById(R.id.loc);
emailEt=findViewById(R.id.email);
passEt=findViewById(R.id.password);
logIn=findViewById(R.id.signin);
disLoc=findViewById(R.id.textView1);
disEm=findViewById(R.id.textView2);
disPass=findViewById(R.id.textView3);
logIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (location.getText().length() != 0 && location.getText().toString() != "" ||
emailEt.getText().length() != 0 && emailEt.getText().toString() != ""||
passEt.getText().length() != 0 && emailEt.getText().toString() != "") {
loc=location.getText().toString();
em=emailEt.getText().toString();
pass=passEt.getText().toString();
AsyncCallWS task=new AsyncCallWS();
task.execute();
}
else
{
Toast.makeText(getApplicationContext(), "Please fill all fields", Toast.LENGTH_LONG).show();
}
}
});
}
private class AsyncCallWS extends AsyncTask<String,Void, Void>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
//progressBar.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
//disLoc.setText(displayLocation);
//progressBar.setVisibility(View.INVISIBLE);
if(!errored)
{
if(displayLocation)
{
Toast.makeText(getApplicationContext(),"Login Succesful", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(),"Login Failed, Try again", Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(getApplicationContext(),"Error occured in invoking webservice", Toast.LENGTH_LONG).show();
}
errored=false;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
@Override
protected Void doInBackground(String... strings) {
displayLocation=WebService.invokeHelloWorldWS(em, pass, loc,"Login");
return null;
}
}
}
将您使用的网址从 http 更改为 https。