2

I'm trying to make the same project to work with WCF and MVC.

My problem is:

MVC is working perfectly, than I included the interface and the .svc that I had in WCF service.

When I try something like this:

http://localhost:2986/PAGENAME.svc

I get the following error:

The resource cannot be found.

NOTE: PAGENAME.svc is in root (and so as the interface).

Looking forward this problem, I included the ignore methods in RegisterRoutes:

routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
routes.IgnoreRoute("{resource}.svc");

But didn't work either =/

Does anyone know how to fix this?

Thank you!

2 Answers 2

2

You need to make sure that you have all the files required, which are referenced from the Service Host (.svc file), i.e.:

<@% ServiceHost Service="..."/>

Where Service specifies the service implementation. The service contract (the interface that the service implementation implements) is usually configured in web.config.

You don't need to ignore the route if the service host file is at the root of your solution.

You need to reference System.ServiceModel.

If you want to test your service you can by opening visual studio command prompt and running wcftestclient, File -> Add service and add the url for your service, e.g.:

http://locahost:12423/MyService.svc
Sign up to request clarification or add additional context in comments.

10 Comments

I have the reference for "System.ServiceModel" =) And I have the service implementation too (the service is using a lib that MVC uses too) Interface is there either =/
Make sure that the right http handler is being called. It should be the one that handles .svc file extension. This is basicaly the same as saying that you should make sure your ignore route is working properly. If it's any help, you can check which handler is being called in IIS: serverfault.com/questions/350318/…
Maybe a safer IgnoreRoute is: {*url}.svc. * means ignore the "/". See stackoverflow.com/questions/3156204/…. Also the order of the routes is important, so make sure you put that one first
"routes.IgnoreRoute("{*url}.svc");" didn't work either (and it is the first one) =,( I'm so lost hahaha... thank you for the article @Rui... at least I'm learning =D
Open visual studio command prompt and type wcftestclient, add the url for the svc file (File -> Add service). You can then test the service
|
2

It's been a while since I've played with this, but I think when using MVC you need to register a service route... but I don't remember if that's what I had to do or if I just wanted to do that for cleaner routes.

To add a service using a service route, you would do something like the following

routes.Add("MyService", new ServiceRoute(
    "some/path",
    new ServiceHostFactory(),
    typeof(MyService)
));

7 Comments

That would eliminate the need for an .svc file
Ah that sounds right, it's been a while since I've played with WCF
Yep.. I don't want to eliminate the .svc file =/ ...Actually I want both possibilities.. using SOAP and HTTP =)
Do I have to add a route for .svc file?
@BrenoRiba the route can stand in for the .svc file, so you wouldn't need it there. The service file just provides information for asp.net like the service type and what not, and that's what the service route does as well. It also allows you to put the route as whatever you would like, rather than where you put the .svc file at.
|

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.