1

I have an ASP.NET MVC application that communicates with a WCF service hosted locally. Currently, I consume the WCF service using a Service Reference added via Visual Studio.

The problem is: every time I close and reopen my ASP.NET MVC project, I have to delete the existing service reference and add it again to avoid errors and outdated metadata issues. This breaks my workflow and is very frustrating.

I want a stable solution that allows me to call the WCF service without needing to re-add the service reference repeatedly.

How can I properly consume the WCF service in my ASP.NET MVC app so that the client proxy doesn’t require re-adding every time I reopen the project?

Here's what I currently do in the controller:

using (var client = new SubmissionServiceClient())
{
    var result = client.SubmitForm(model);
    // ...
}

But this causes issues after closing and reopening the project.

3
  • What changes when you add the new service reference? Which of the ABC (Address, Binding, Contract) has to change? Commented May 25 at 7:28
  • None of the ABCs change. The address stays the same, binding is still basicHttpBinding, and the contract hasn’t changed. The issue seems to be with the generated service reference becoming stale or invalid when reopening the project. Commented May 29 at 9:52
  • make sure the service reference files are being created in the same folder path as your project and also make sure that your source control is not ignoring these files. Commented Jul 24 at 15:39

1 Answer 1

2

Yep, I’ve run into this before. Usually it happens when the WCF service reference files aren’t properly saved or included in the project.

A few things to check:

  1. Make sure the generated files are there (like Reference.cs, .svcmap, etc.) inside the Service References/<YourService> folder, and that they’re actually included in the project (not just sitting in the folder).

  2. Check your web.config. when you add a service reference, it writes endpoint configs there. If those are missing or didn’t get saved, the proxy won’t work next time you open the project. If it keeps happening, you can try using svcutil.exe to generate the proxy manually instead of relying on the “Add Service Reference” tool.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.