Hosting WCF services
I have been working on a Silverlight app that consumes a WCF service. [on Visual Studio]
as a ma开发者_Python百科tter of simplicity I created a WCF service in the project itself [as-in I didnt host it in IIS, but let the build-in webdev server in VS do it for me]
It works well, now I want to deploy it on IIS 7.0, can you tell me If i would need to host the service independently and then the remaining stuff or if I just publish the website, the service would be hosted too and the Silverlight client would be able to communicate with the service.
Please help!
Thanks
You basically need
- a virtual directory in IIS 7
- a SVC file (service file) that instructs IIS how to instantiate your service
You basically have three options to deploy your service implementation:
you can put your service implementation into the code-behind file of the SVC file - that would be my least favourable option - basically don't do it - it gets messy and offers no benefit
you can put your service class file (the MyService.cs file) and the interface file (IMyService.cs) into the
App_Code
directory (if you're using a Web Site project type) - again, I don't particularly like this approachyour best option: put your service contract (the interface) and your service implementation into a separate class-library assembly for that service, and deploy that
MyService.dll
into the.\bin
directory below the virtual directory where your SVC file lives.
Then add a *.svc file (pure text file) to your virtual directory, which contains:
<%@ServiceHost language="c#" Debug="true" Service="MyService" %>
And of course, you need the appropriate web.config entries - but I'm sure you already have those, right?
Your service address now is:
http://YourServer/VirtualDirectory/YourService.svc
For more info, see How to: Host a WCF Service in IIS
Marc got you the how. In response to your question around need, you will both need and want to separate the services from the Silverlight assets (static references and XAPs). This might not make a lot of sense for smaller sites but as you grow in size this affords you the opportunity to locate your Silverlight assets on a location separate from your services (such as a content distribution network) so that they can be delivered to users as fast as possible.
精彩评论