Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
    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();
        }
    }

// Interface contract

    [ServiceContract]
    public interface IReservationService
    {
        [OperationContract]
        List<Business.Reservation> RequestReservationRetrieval();
    }


And this is the Desktop Application's section that consumes the web service:

C#
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:

C#
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:

XML
<connectionStrings>
  <add name="ReservationDbContext" connectionString="Data Source=JUAN-PC\SQLEXPRESS;Initial Catalog=WebApplication;Uid=**;Pwd=****;" providerName="System.Data.SqlClient" />
  <!-- <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20140926013844.mdf;Initial Catalog=aspnet-WebApplication1-20140926013844;Integrated Security=True" 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.
Posted
Comments
Dominic Burford 28-Oct-14 4:37am    
The WCF service works as expected when it's invoked directly from Visual Studio? Can you check your client config to ensure that you are connecting to the correct WCF endpoint.

It might be worth creating a self-hosting console app for your WCF service for debugging purposes. This is how I debug my WCF services before I deploy them to IIS. This is to ensure that the WCF service works correctly when run from a client, in addition to the unit tests that run the code directly from the service. Creating a WCF self-hosted console app is easy and should allow you to properly debug your problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900