views:

330

answers:

4

I have a Silverlight web app solution with a Silverlight-enabled WCF service included. Everything has worked fine for the past 6 months or so. I can access data through the service with no problem.

I came into work today, opened up the solution, ran it again, and suddenly, there's a mismatch between the WCF service port and the port that Silverlight wants to use to access the service.

How and why would the port suddenly change?

How do you specify a port to use? I never specified a port in the past--it just worked. I can't find a port specification in the web.config or the service CS file.

A: 

Is the WCF service hosted in IIS ? Has someone changed some IIS configuration?

When hosting in IIS, the IIS server name, port, virtual directory and name and location of the *.svc file define your service address on the server side. If any of those changes --> your service won't be available anymore.

marc_s
+1  A: 

Are you using the built-in Cassini web server? And is the WCF web service a part of the same web project as your hosting page? Or is it a separate project?

If you're using Cassini, the port at which it listens in a dev environment is specified in the project properties page, on the "Web" tab. Normally Visual Studio auto-assigns a port, but if you're using this as your web service, you'll want to tell it which specific port to use (e.g., 51000 or something). It might always have defaulted to the same port, but if it detects that this port is in use (perhaps by another Cassini instance on your machine that never exited), it would switch ports.

You should also check the ServiceReferences.ClientConfig file in your Silverlight project to see what port it's trying to connect to.

Ken Smith
Don't know if this is good practice, but I up-voted this answer because the scenario you describe (where the port was in use because another instance of the app didn't exit properly) was most likely what happened. This answer adds useful diagnostic info to the answer I accepted.
Klay
There are other benefits to specifying a port, for instance, being able to write integration tests that are able to call the service reliably without configuration changes. It's what I generally do when I'm working with combined Silverlight/ASP.NET/WCF projects.
Ken Smith
+2  A: 

Sounds like you are talking about a solution inside visual studio, you can view the default port by clicking Web project property, go to the Web tab, inside the "Servers" section you will see the default port number, you manually assign a specific port or use auto-assign port.

I have seen similar situation before, it happened when the port is being used. You can reassign the port by changing the port number in project property, recompile web solution then update the web service reference in your client project. Hope it helps.

Jay Zeng
This is it exactly. I know I had seen a place to set a specific port, but I couldn't find it until about 30 seconds after I posted this question. Apparently my timing was just a little off.
Klay
A: 

You might have some other software that started using the port (Skype has caught me out in the past)

Mark Cooper