Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. namespace WebService3
  2. {
  3. [WebService(Namespace = "http://tempuri.org/")]
  4. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  5. [System.ComponentModel.ToolboxItem(false)]
  6. // [System.Web.Script.Services.ScriptService]
  7.  
  8.  
  9. class DBConnect
  10. {
  11. private MySqlConnection connection;
  12. private string server;
  13. private string database;
  14. private string uid;
  15. private string password;
  16. }
  17.  
  18. private void Initialize()
  19. {
  20. server = "localhost";
  21. database = "eagles_db";
  22. uid = "root";
  23. password = "";
  24. string connectionString;
  25. connectionString = "SERVER=" + server + ";" + "DATABASE=" +
  26. database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
  27.  
  28. connection = new MySqlConnection(connectionString);
  29. }
  30.  
  31. public XmlDocument abmeldungen()
  32. {
  33. XmlDocument doc = new XmlDocument();
  34. XmlNode root;
  35. XmlNode tempHeader;
  36. XmlNode tempInhalt;
  37.  
  38. List<int> lstIDs = new List<int>();
  39. List<string> lstNamen = new List<string>();
  40. string ausgabe = string.Empty;
  41.  
  42.  
  43.  
  44. string conStr = ConfigurationManager.ConnectionStrings["dbstring"].ConnectionString;
  45.  
  46. 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";
  47.  
  48.  
  49.  
  50. MySql.Data.MySqlClient.MySqlCommand cmd = new MySqlCommand(befehl, connection);
  51.  
  52.  
  53.  
  54. connection.Open();
  55.  
  56. MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader();
  57.  
  58.  
  59.  
  60. root = doc.CreateElement("Abmeldungen");
  61. doc.AppendChild(root);
  62.  
  63.  
  64. tempHeader = doc.CreateElement("Abmeldungen"); //doc.CreateElement(reader["reportTitle"].ToString());
  65.  
  66. root.AppendChild(tempHeader);
  67.  
  68. while (reader.Read())
  69. {
  70. tempInhalt = doc.CreateElement("Name");
  71. tempHeader.AppendChild(tempInhalt).InnerText = reader["name"].ToString();
  72.  
  73. tempInhalt = doc.CreateElement("Grund");
  74. tempHeader.AppendChild(tempInhalt).InnerText = reader["grund"].ToString();
  75.  
  76. tempInhalt = doc.CreateElement("datum");
  77. tempHeader.AppendChild(tempInhalt).InnerText = reader["datum"].ToString();
  78.  
  79. tempInhalt = doc.CreateElement("erstellt");
  80. tempHeader.AppendChild(tempInhalt).InnerText = reader["cf_created"].ToString();
  81. }
  82.  
  83. reader.Close();
  84.  
  85. connection.Close();
  86.  
  87. return doc;
  88.  
  89. }
  90.  
  91. [WebMethod]
  92. public XmlDocument abmeldung()
  93. {
  94. DBConnect con1 = new DBConnect();
  95. return con1.abmeldungen();
  96. }
  97.  
  98. package de.maturaprojekt.sema;
  99.  
  100. import org.ksoap2.SoapEnvelope;
  101. import org.ksoap2.serialization.PropertyInfo;
  102. import org.ksoap2.serialization.SoapObject;
  103. import org.ksoap2.serialization.SoapSerializationEnvelope;
  104. import org.ksoap2.transport.HttpTransportSE;
  105.  
  106.  
  107. import android.os.Bundle;
  108. import android.app.Activity;
  109. import android.util.Log;
  110. import android.view.Menu;
  111. import android.view.View;
  112. import android.widget.Toast;
  113.  
  114.  
  115. public class Abmeldungen extends Activity {
  116.  
  117. public static String NAMESPACE = "http://tempuri.org/";
  118. public static String SOAP_ACTION = "http://10.0.2.2:28266/Service1.asmx/abmeldung";
  119. public static String METHOD_NAME = "abmeldung";
  120.  
  121. public static String URL = "http://10.0.2.2:28266/Service1.asmx";
  122.  
  123. public static String response;
  124.  
  125. public static String abmeldungen1()
  126. {
  127. //SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  128.  
  129. return "Error";
  130. }
  131.  
  132. public static String abmeldungen()
  133. {
  134.  
  135.  
  136. SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  137.  
  138.  
  139. SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  140.  
  141. envelope.setOutputSoapObject(request);
  142.  
  143. try
  144. {
  145. HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
  146.  
  147. androidHttpTransport.call(SOAP_ACTION, envelope);
  148.  
  149. // SoapResult
  150. SoapObject result = (SoapObject)envelope.getResponse(); //body.In
  151.  
  152.  
  153. if (result != null)
  154. {
  155. response=result.toString(); //getProperty(0)
  156.  
  157. if(response.equals("false"))
  158. {
  159. return "Error";
  160. //error,
  161. }
  162.  
  163. else
  164. {
  165. return "IT WORKS";
  166. // everything works correctly
  167. }
  168.  
  169. }
  170.  
  171. else
  172. {
  173. return "ERROR2";
  174. // no answer from webservice
  175. }
  176. }
  177.  
  178. catch (Exception exc)
  179. {
  180. Log.i("tom",exc.toString());
  181. return "ERROR3";
  182. // andere Probleme
  183. }
  184.  
  185.  
  186.  
  187. }
  188.  
  189.  
  190. @Override
  191. protected void onCreate(Bundle savedInstanceState) {
  192. super.onCreate(savedInstanceState);
  193. setContentView(R.layout.activity_abmeldungen);
  194. }
  195.  
  196. public void btn_abfragen(View view)
  197. {
  198. //Toast.makeText(this, "abgerufen", Toast.LENGTH_SHORT).show();
  199. String return22 = abmeldungen();
  200.  
  201. Toast.makeText(this,return22, Toast.LENGTH_LONG).show();
  202.  
  203. }
  204.  
  205.  
  206.  
  207. @Override
  208. public boolean onCreateOptionsMenu(Menu menu) {
  209. // Inflate the menu; this adds items to the action bar if it is present.
  210. getMenuInflater().inflate(R.menu.abmeldungen, menu);
  211. return true;
  212. }
  213. }
  214.  
  215. public static String SOAP_ACTION = "http://10.0.2.2:28266/Service1.asmx/abmeldung";
  216.  
  217. "http://tempuri.org/Service1/abmeldung"
  218.  
  219. http://10.0.2.2:28266/Service1.asmx
  220.  
  221. <wsdl:binding name="BasicHttpBinding_Service1" type="tns:example">
  222. <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
  223. <wsdl:operation name="ambeldung">
  224. <soap:operation soapAction="http://tempuri.org/examplesoapaction/example" style="document"/>
  225. ......
  226. ......
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement