TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sam Mettenmeyer
NA
108
11.1k
Connect to Microsoft SQL Server 2012 with WCF web service
Nov 20 2018 10:18 AM
I am trying to connect an Microsoft SQL Server 2012 database to an Xamarin.Android app.
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:
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<AdrSuche1> GetAdrSuche1()
{
List<AdrSuche1> adrList =
new
List<AdrSuche1>();
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();
}
}
}
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;
namespace
TestWcfService
{
public
interface IService1
{
[OperationContract]
[WebGet(UriTemplate =
"GetAdrSuche1"
)]
List<AdrSuche1> 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
Reply
Answers (
4
)
How to pass the header, body data while using postmethod api
getting null when send image in angular6 to mvc API