As internet researches told me that it is not possible to connect directly to an external database in Xamarin and that I need a layer between my app and the database, I tried to implement that needed WebService with the help of
https://www.youtube.com/watch?v=xnO9MbferQo
Unfortunately, when I try to run (pressing F5 in Visual Studio) this web service, he opens the WCF-TestClient (as it should be), but after maybe after half of the progress bar ("is adding"), an error view is showed, saying:
Warnung: Es wurde kein Code generiert. Wenn Sie versucht haben, einen Client zu generieren, könnte die Ursache hierfür sein, dass die Metadatendokumente keine gültigen Verträge oder Dienste enthielten oder dass erkannt wurde, dass sich alle Verträge/Dienste in /reference-Assemblys befinden. Stellen Sie sicher, dass alle Metadatendokumente an das Tool übergeben wurden. Warnung: Wenn Datenverträge aus Schemas generiert werden sollen, müssen Sie sicherstellen, dass die Option /dataContractOnly verwendet wird.
Sorry for this German. I try to translate it for you:
Warning: No code has been generated. If you tried to generate a client, a possible reason for this could be, that the meta data documents do not contain valid contracts or services or that all contracts/services are lying in /reference-Assemblys. Please make sure, that all meta data documents are transfered to the tool.
Warning: If data contracts are generated from a schema, you have to make sure, that the option /dataContractOnly is used.
Please let me share my code:
Service1.svc.cs:
IService1.cs: - using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.Text;
- using System.Data;
- using System.Data.SqlClient;
- namespace TestWcfService
- {
- public class Service1 : IService1
- {
- // Connection string
- private readonly string conStr = "data source = [Server-IP]\\[instance_name]; initial catalog = [catalog_name]; user id = [dbusername]; password = [dbpw]; Connect Timeout = 60"";
- public List
GetAdrSuche1() - {
- List
adrList = new List (); - SqlConnection con = new SqlConnection(conStr);
- con.Open();
- SqlCommand cmd = new SqlCommand("SELECT * FROM adressen", con)
- {
- CommandType = CommandType.Text
- };
- SqlDataReader reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- AdrSuche1 adrSuche1 = new AdrSuche1
- {
- Adrsuche1 = reader["adrsuche1"].ToString()
- };
- adrList.Add(adrSuche1);
- }
- return adrList.ToList();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.ServiceModel.Web;
- using System.Text;
- namespace TestWcfService
- {
- public interface IService1
- {
- [OperationContract]
- [WebGet(UriTemplate = "GetAdrSuche1")]
- List
GetAdrSuche1(); - }
- [DataContract]
- public class AdrSuche1
- {
- string adrsuche1;
- [DataMember]
- public string Adrsuche1
- {
- get { return adrsuche1; }
- set { adrsuche1 = value; }
- }
- }
- }
What is the problem? Can anyone maybe help me integrating Web Api or WCF Service so I can read data from external database and display them on my app?
Best regards
Ahsan SiddiquePosted Nov 20, 2018, 2:50 PM
Sam MettenmeyerPosted Nov 23, 2018, 3:16 AM
Ahsan SiddiquePosted Nov 21, 2018, 3:45 AM
Sam MettenmeyerPosted Nov 21, 2018, 3:41 AM
Unfortunately, you got me a little wrong:
I do not want to create a new database (particularly to use Azure database as expected, a payment is required, or at least by signing up one has to give credit card data which I don't have).