Hello, I'm new to this forum but I'm hoping you guys can help me out with this!
I've got a WCF Web Service which is supposed to retrieve the rows of a Web Application's database and add them to a Desktop Application's Local Database.
Now, I've made the Web Service and when I debug it and invoke it through the interface of the debugger it does indeed retrieve the rows of the Web Application's database, but when I use it with the Desktop Application, for some reason it retrieves the rows of the Desktop Application's database. This is an odd behavior because I specifically set in the Web Service's App.config that it must connect to the Web Application's database.
Here's the involved code:
Web Service
public class ReservationService : IReservationService, IDisposable
{
ReservationRepository repo;
public List<Business.Reservation> RequestReservationRetrieval()
{
using (repo = new ReservationRepository())
{
List<Reservation> reservations = repo.ObtainReservations();
return reservations;
}
}
public void Dispose()
{
repo.Dispose();
}
}
[ServiceContract]
public interface IReservationService
{
[OperationContract]
List<Business.Reservation> RequestReservationRetrieval();
}
And this is the Desktop Application's section that consumes the web service:
private void ReservationObtainButton_Click(object sender, EventArgs e)
{
try
{
using(ReservationRepository repository = new ReservationRepository())
{
List<Reservation> webReservations;
using(ReservationService rs = new ReservationService())
{
webReservations = rs.RequestReservationRetrieval();
}
foreach (Reservation r in webReservations)
{
repository.InsertReservation(r);
}
ReservationDataGridView.DataSource = repository.ObtainReservations();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
What's the most important to me right now is that for some reason this section:
List<Reservation> webReservations;
using(ReservationService rs = new ReservationService())
{
webReservations = rs.RequestReservationRetrieval();
}
Somehow retrieves the local database's (the one that belongs to the desktop application) rows, when it's set to retrieve the ones from the web application.
To corroborate I checked the App.Config in the web service:
<connectionStrings>
<add name="ReservationDbContext" connectionString="Data Source=JUAN-PC\SQLEXPRESS;Initial Catalog=WebApplication;Uid=**;Pwd=****;" providerName="System.Data.SqlClient" />
</connectionStrings>
I've reached the point where I have no idea why this is happening, so here I am asking you guys.
Hope you can help me, and thanks for giving it a read.