I have a C# Webservice and an Eclipse Android Application project. I am trying to get a xml file from the webservice with KSOAP2 version 2.3. The webservice works and gives me back the current xml document and it also seems like i get a connection to the webservice with the android application, but i always get an exception saying that the webservice does not recognize the value of the HTTP Header "SOAPAction".
Webservice:
namespace WebService3
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// [System.Web.Script.Services.ScriptService]
class DBConnect
{
private MySqlConnection connection;
private string server;
private string database;
private string uid;
private string password;
}
private void Initialize()
{
server = "localhost";
database = "eagles_db";
uid = "root";
password = "";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
}
public XmlDocument abmeldungen()
{
XmlDocument doc = new XmlDocument();
XmlNode root;
XmlNode tempHeader;
XmlNode tempInhalt;
List<int> lstIDs = new List<int>();
List<string> lstNamen = new List<string>();
string ausgabe = string.Empty;
string conStr = ConfigurationManager.ConnectionStrings["dbstring"].ConnectionString;
string befehl = "Select abmeldung.cf_created, abmeldung.datum, abmeldung.grund, web_users.name From abmeldung Inner Join web_users On abmeldung.cf_user_id = web_users.id Order By abmeldung.cf_created Desc";
MySql.Data.MySqlClient.MySqlCommand cmd = new MySqlCommand(befehl, connection);
connection.Open();
MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader();
root = doc.CreateElement("Abmeldungen");
doc.AppendChild(root);
tempHeader = doc.CreateElement("Abmeldungen"); //doc.CreateElement(reader["reportTitle"].ToString());
root.AppendChild(tempHeader);
while (reader.Read())
{
tempInhalt = doc.CreateElement("Name");
tempHeader.AppendChild(tempInhalt).InnerText = reader["name"].ToString();
tempInhalt = doc.CreateElement("Grund");
tempHeader.AppendChild(tempInhalt).InnerText = reader["grund"].ToString();
tempInhalt = doc.CreateElement("datum");
tempHeader.AppendChild(tempInhalt).InnerText = reader["datum"].ToString();
tempInhalt = doc.CreateElement("erstellt");
tempHeader.AppendChild(tempInhalt).InnerText = reader["cf_created"].ToString();
}
reader.Close();
connection.Close();
return doc;
}
[WebMethod]
public XmlDocument abmeldung()
{
DBConnect con1 = new DBConnect();
return con1.abmeldungen();
}
everything works in firefox and i get the correct Xml document
Application:
package de.maturaprojekt.sema;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
public class Abmeldungen extends Activity {
public static String NAMESPACE = "http://tempuri.org/";
public static String SOAP_ACTION = "http://10.0.2.2:28266/Service1.asmx/abmeldung";
public static String METHOD_NAME = "abmeldung";
public static String URL = "http://10.0.2.2:28266/Service1.asmx";
public static String response;
public static String abmeldungen1()
{
//SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
return "Error";
}
public static String abmeldungen()
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
try
{
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapResult
SoapObject result = (SoapObject)envelope.getResponse(); //body.In
if (result != null)
{
response=result.toString(); //getProperty(0)
if(response.equals("false"))
{
return "Error";
//error,
}
else
{
return "IT WORKS";
// everything works correctly
}
}
else
{
return "ERROR2";
// no answer from webservice
}
}
catch (Exception exc)
{
Log.i("tom",exc.toString());
return "ERROR3";
// andere Probleme
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_abmeldungen);
}
public void btn_abfragen(View view)
{
//Toast.makeText(this, "abgerufen", Toast.LENGTH_SHORT).show();
String return22 = abmeldungen();
Toast.makeText(this,return22, Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.abmeldungen, menu);
return true;
}
}
I used 10.10.2.2 as localhost because on the emulated android device the normal "localhost" would be localhost of the emulated device and 10.10.2.2 is the right localhost.
I hope my question isn't too confusing, i would appreciate it very much if anybody could help me. Thank you
public static String SOAP_ACTION = "http://10.0.2.2:28266/Service1.asmx/abmeldung";
I think your soap action should be something like,
"http://tempuri.org/Service1/abmeldung"
You need to check this in your wsdl.
Open your wsdl in browser using,
http://10.0.2.2:28266/Service1.asmx
Search wsdl:binding tag in wsdl.
Within binding tag search for operation ambeldung
You can find your SOAP Action defined as,
<wsdl:binding name="BasicHttpBinding_Service1" type="tns:example">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ambeldung">
<soap:operation soapAction="http://tempuri.org/examplesoapaction/example" style="document"/>
......
......