When i'm trying to invoke my web service(in.NET asmx) from Android Java ... I'm getting
this error -> 500 Internal Server Error.
-> Response{protocol=http/1.1, code=500, message=Internal Server Error, url=http://example.in/webservice/login.asmx}
here is my Login Activity..
/*==========================================================================================================================*/
public class Login_page extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_page);
phoneNoET = (EditText) findViewById(R.id.editText);
userNameET = (EditText) findViewById(R.id.editText1);
passWordET = (EditText) findViewById(R.id.editText2);
b = (Button) findViewById(R.id.login);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
login();
}
});
}
public void login() {
Map<String, String> loginMap = new LinkedHashMap<>();
String phonenumber, Username, Userpassword;
phonenumber = phoneNoET.getText().toString();
Username = userNameET.getText().toString();
Userpassword = passWordET.getText().toString();
loginMap.put("phonenumber", phonenumber);
loginMap.put("Username", Username);
loginMap.put("Userpassword", Userpassword);
try {
Services apiService = ApiHandler.getApiService();
final Call<LoginModel> loginCall = apiService.Login_web(loginMap);
loginCall.enqueue(new Callback<LoginModel>()
{
@Override
public void onResponse(Call<LoginModel> call, Response<LoginModel> response)
{
if (response.isSuccessful())
{
LoginModel loginModel = response.body();
if (loginModel != null) {
Log.d("Login_web", "response" + loginModel);
}
}
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}
/*==========================================================================================================================*/
public class ApiHandler
{
private static final String DEV_BASE_URL = "http://example.in/webservice/";
private static final long HTTP_TIMEOUT = TimeUnit.SECONDS.toMillis(600);
private static Services apiService;
private static Retrofit.Builder builder = new Retrofit.Builder().baseUrl(DEV_BASE_URL).addConverterFactory(GsonConverterFactory.create());
private static OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
public static Services getApiService()
{
if (apiService == null)
{
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
httpClient.addInterceptor(logging);
Retrofit retrofit = builder.client(httpClient.build()).build();
apiService = retrofit.create(Services.class);
return apiService;
} else
{
return apiService;
}
}
}
/*==========================================================================================================================*/
public interface Services {
@FormUrlEncoded
@POST("login.asmx")
Call<LoginModel> Login_web(@FieldMap Map<String, String> map);
}
/*==========================================================================================================================*/
public class LoginModel implements Serializable {
@SerializedName("Bank_ID")
@Expose
public String Bank_ID;
public String getBank_ID() {
return Bank_ID;
}
public void setBank_ID(String Bank_ID) {
this.Bank_ID = Bank_ID;
}
}
/*==========================================================================================================================*/
Not a android expert, but you can call .NET .asmx using KSOAP , here are the few links which have explained it very well
http://programmerguru.com/android-tutorial/how-to-call-asp-net-web-service-in-android/ (You can also download demo source code and try to call your .asmx by changing url and class as required.)
https://www.codeproject.com/Articles/304302/Calling-Asp-Net-Webservice-ASMX-From-an-Android-Ap
https://www.journaldev.com/13639/retrofit-android-example-tutorial (Retrofit example which you are using, you can try demo source code of this project also which is provided in the link and execute it locally by changing required url and class)
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly