2009
07.25

I recently made a WCF Service for the company i work for. I had it all working on my own computer so it was about time to put the service online.
This proved to be pretty difficult, the more because Microsoft doesn’t realy give a good explanation on MSDN about how to do this.

I struggled about a day to get it right. Mostly because i’m not as witty as the people down in Redmond though.
Anyway; i’ll give you a step-by-step overview on how to get your code working on a live server in the hopes of saving atleast one person a headache.

First of all it’s a good idea to make it work on your local computer. This will save you some trouble of uploading to your server and rdp’ing constantly.
What you’ll need:

  • IIS 7 installed along with all the WCF features
  • Visual Studio 2008
  • Your WCF service; compiled in “Release”
  • A fair amount of optimism

As you can see in the tutorial on MSDN they expect you to manually create an App_Folder and put your script files in there. Allthough it’s a complete valid way (or is it? do we like to have .cs files to mess around with?) of working, i think us programmers will rarely handle it this way.
Most likely you will have built your Service in Visual Studio, added a seperate consuming client in the same solution and it magically works. When you want to deploy all of it live things are quiet different and chances are that your client application won’t be on the same server as well.

So here’s what we’ll do:

Setting up the WCF Service in IIS7:

Start off by creating an application pool for your Service in IIS7

addpool

Next we’ll create the folder in which the service will reside. Make sure IIS_IUSRS has “Read & Execute “, “List folder contents” and “Read” on this folder. (i took C:\myservice as folder)

Now we’ll create a new Website in IIS and we’ll make it point to our freshly created folder

addwebsite

I put the port on 8000 as to not interfere with the website traffic that’s passing along through gate 80.

Now this will not work yet because we need to activate WCF for IIS7 manually. This we will do by running the following command in cmd:
“%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe” -r -y

We’re done configuring IIS!

Preparing our Webservice to be served in IIS:

Navigate in your Windows Explorer to the folder you created for hosting the service in. Create a folder named “Bin” and copy your .dll files into that folder.
(C:\myservice\Bin in my case)

Navigate back to your folder (the parent of your new Bin folder that is) and create a file called yourservice.svc (replace yourservice with.. you know.. your service name).
I did this by creating a .txt file and changing the extension to .svc .

I know this is a bit weird but it’s the way to go.
In your .svc file you can copy this:

<% @ServiceHost Service=”YourServiceNameSpace.YourServiceName” %>

Change the Service attribute accordingly to your needs ofcourse.
That’s all that has to come inside the .svc file.

Next, create a web.config file in the same folder as the .svc file and edit it:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<connectionStrings>
<add name=”DidierDB” connectionString=”Data Source=\\SRV-TEST\Advantage\DB Didier\CARFAC.ADD;User ID=AdsSys” providerName=”Advantage.Data.Provider” />
<!–<add name=”DidierDB” connectionString=”Data Source=C:\CarNet\Database\CarsOne\CARFAC.ADD;User ID=AdsSys” providerName=”Advantage.Data.Provider” />–>
</connectionStrings>
<system.web>
<compilation debug=”false” />
</system.web>
<!– When deploying the service library project, the content of the config file must be added to the host’s
app.config file. System.Configuration does not support config files for libraries. –>
<system.serviceModel>
<services>
<service name=”CarProviderService.CarService” behaviorConfiguration=”CarProviderService.CarServiceBehavior”>
<host>
<baseAddresses>
<add baseAddress = “http://localhost:8000/” />
</baseAddresses>
</host>
<!– Service Endpoints –>
<!– Unless fully qualified, address is relative to base address supplied above –>
<endpoint address =”" binding=”wsHttpBinding” contract=”CarProviderService.ICarService”>
<!–
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
automatically.
–>
<identity>
<dns value=”localhost”/>
</identity>
</endpoint>
<!– Metadata Endpoints –>
<!– The Metadata Exchange endpoint is used by the service to describe itself to clients. –>
<!– This endpoint does not use a secure binding and should be secured or removed before deployment –>
<endpoint address=”mex” binding=”mexHttpBinding” contract=”IMetadataExchange”/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name=”CarProviderService.CarServiceBehavior”>
<!– To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment –>
<serviceMetadata httpGetEnabled=”True”/>
<!– To receive exception details in faults for debugging purposes,
set the value below to true.  Set to false before deployment
to avoid disclosing exception information –>
<serviceDebug includeExceptionDetailInFaults=”False” />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>


  
    
  
  
  
    
      
        
          
            
          
        
        
        
        
          
          
            
          
        
        
        
        
        
      
    
    
      
        
          
          
          
          
        
      
    
  

Change this according to your namespace and service name ofcourse.

And finally, if you did it all correctly, you should be able to surf to  http://localhost:8000/yourservice.svc and you should arrive on the webservice page.

This means total and utter succes. :-)

If i have made any mistakes or forget to mention anything please let me know.

  • Share/Bookmark

No Comment.

Add Your Comment