javaandroid:使用SOAP从Webservice获取Xml文件
我有一个C#Webservice和一个EclipseAndroid应用程序项目。我正在尝试使用KSOAP2版本2.3从Web服务获取xml文件。webservice可以工作并返回当前的xml文档,看起来我还可以通过android应用程序连接到webservice,但我总是收到一个异常,说webservice无法识别HTTP头“SOAPAction”的值 网络服务:javaandroid:使用SOAP从Webservice获取Xml文件,java,android,web-services,soap,ksoap2,Java,Android,Web Services,Soap,Ksoap2,我有一个C#Webservice和一个EclipseAndroid应用程序项目。我正在尝试使用KSOAP2版本2.3从Web服务获取xml文件。webservice可以工作并返回当前的xml文档,看起来我还可以通过android应用程序连接到webservice,但我总是收到一个异常,说webservice无法识别HTTP头“SOAPAction”的值 网络服务: namespace WebService3 { [WebService(Namespace = "http:
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();
}
我使用10.10.2.2作为localhost,因为在模拟的android设备上,正常的“localhost”将是模拟设备的localhost,而10.10.2.2是正确的localhost
我希望我的问题不要太混乱,如果有人能帮助我,我将不胜感激。多谢各位
public static String SOAP_ACTION = "http://10.0.2.2:28266/Service1.asmx/abmeldung";
我觉得你的肥皂剧应该是这样的
"http://tempuri.org/Service1/abmeldung"
您需要在wsdl中检查这一点
使用在浏览器中打开wsdl
http://10.0.2.2:28266/Service1.asmx
搜索wsdl:wsdl中的绑定标记
在绑定标签内搜索“ambeldung”操作
您可以找到定义为的SOAP操作
<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"/>
......
......
......
......
你是从哪里将soap操作复制到代码中的?这是一个学校项目,我从一个较旧的项目中获得了代码,与我的项目类似,他们尝试以相同的方式连接到Web服务。非常感谢!正确的SOAP操作是:“现在它工作了。
<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"/>
......
......