开发者

deploying a web application which references a class library which communicates with a WCF service

开发者 https://www.devze.com 2023-02-07 19:47 出处:网络
I have a separate environment for development. On my production server, where we mostly host web applications开发者_JAVA百科, we deploy the precompiled version of the web project.

I have a separate environment for development. On my production server, where we mostly host web applications开发者_JAVA百科, we deploy the precompiled version of the web project.

While doing development I work on three projects. One is the WCF Service. Two, is the class library project. This library has classes which makes calls on the WCF service. And the third, is a web project which consumes the class library.

The last two projects come under one VS solution. I host the wcf service in the development environment. This service is added as service reference to my class library.

I am unable to visualize what will happen once I add the DLL (viz output of the class library project) to my web project, and, the web project has to be deployed. At the time of deployment I have to change the service reference (the url of the svc file will change as it has to point to the production wcf service). How to go about this? What must I take care when adding the dll to the web project?


Don't worry too much about the DLL. That will take it's configuration from the application that it is running within, be it win forms, web app, web site or windows service. So with that in mind which ever project you added your web service binding to will have an app/web.config containing a system.service model section that you must include in the config file of any applications which use that assembly and will be using the web service.

To change the binding it's in the system.servicemodel section of your web.config

<client>
    <endpoint address="http://blahblah:8000/blah" binding="wsHttpBinding"
        bindingConfiguration="WSHttpBinding_Service1" contract="GenService.Service"
        name="WSHttpBinding_Service" />
</client>

Personally i use config transforms and publish profiles to deploy sites to take the hastle out of setting up the web.config files. So i'll have Web.Production.config

<system.serviceModel>
    <client>
        <endpoint name="WSHttpBinding_Service" address="http://production/blah" xdt:Locator="Match(name)" xdt:Transform="SetAttributes(address)" />
    </client>
</system.serviceModel>

A guide is here http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx


First thing you should know is that configuration file placed in the library project will not be used by the .dll. The DLL will use the web configuration file. So you should configure there the url to the WCF service.

Just copy-paste the information within (included) you have in the DLL Configuration file to the web.config.

Best Regards


As long as you add a referece to your class library within your web application, both dll's will be deployed when you publish your web application project to Production. As far as the WCF url that must change, I'd add the URL as a key within your AppSettings in the web.config file.

Web.config:

<configuration>
   <appSettings>
      <add key="WCF_URL" value="http://url to wcf service"/>
   </appSettings>
//snip..
</configuration>

Code:

// Establish the proxy with the WCF Service that you added as a Web Reference in your solution
WCFService.<class> myWCFService= new WCFService.<class>();
// Check the web.config for the URL to WCF web service
myWCFService.Url = ConfigurationManager.AppSettings["WCF_URL"];
0

精彩评论

暂无评论...
验证码 换一张
取 消