Click here to Skip to main content
15,065,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I'm trying to Host a WCF service on the web Hosting's IIS. But failed to do so. I've a test Service Project which I'm currently trying to Host just for checking purpose. The project runs and host successfully within the Visual Studio 2010 Development environment.

I would really appreciate if You could guide me to the process of Hosting a WCF service. I tried couple of things like create a new directory from the Control Panel's File Manager and Upload the files there, But could be successful. Apparently, The hosting only accepts the "Index" File type to be run like (index.html) when I try to put the service project on the httpdocs folder.T

I googled A lot but the only best thing I could find was hosting locally on IIS. That didn't work as well for me. I'm a newbie to this so Your help would really be appreciated. Thank you.

My hosting domain is "www.collect-info.com‏".

How I'm doing my working:

1. I've created a "WCF Service Library" name as "Collect Info". Here is the App.config code:

<?xml version="1.0"?>
<configuration>

  <connectionStrings>
    <add name="cn" connectionString="Data Source=AHMAD-PC\SQLEXPRESS;Initial Catalog=InfoCollect;Integrated Security=True"/>
  </connectionStrings>
  
  <system.web>
    <compilation debug="true"/>
  </system.web>

<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="CollectInfoSvcWebBehaviour">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="CollectInfoSvcBehaviour">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="CollectInfoSvcBehaviour" name="CollectInfo.InfoCollectService">
        <endpoint address="" behaviorConfiguration="" binding="webHttpBinding"
          bindingConfiguration="" name="InfoCollectSvcWebHttp" contract="CollectInfo.IInfoCollectService"
          isSystemEndpoint="false" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
          name="CollectInfoSvcMexEndPoint" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/CollectInfoSvc/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>

2. I included the Service Reference of the WCF library on the WCF project. After that, I created another project of "WCF Project" and removed it's default IService.cs file and changed the mark up of the Service1.svc to point to the ServiceClass.cs of the Service Library.

Markeup:
<%@ ServiceHost Service="CollectInfo.InfoCollectService" %>


Web.config File :
<?xml version="1.0"?>
<configuration>
  <appSettings/>
  <connectionStrings/>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
    <authentication mode="Windows"/>
    <!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
         <error statusCode="403" redirect="NoAccess.htm" />
         <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
    -->
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web>
  <!-- 
      The system.webServer section is required for running ASP.NET AJAX under Internet
      Information Services 7.0.  It is not necessary for previous version of IIS.
  -->
  <system.serviceModel>
    <services>
      <service name="CollectInfo.InfoCollectService" behaviorConfiguration="CollectInfoHost.Service1Behavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding" contract="CollectInfo.IInfoCollectService">
          <!-- 
              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>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CollectInfoHost.Service1Behavior">
          <!-- 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>
Posted
Updated 30-Jul-13 8:11am
v4
Comments
[no name] 30-Jul-13 11:12am
   
Maybe you should talk to your hosting provider.
Member 9568921 30-Jul-13 11:15am
   
I did talk to them, They just say that Host any "Index" file on httpdocs folder. The problem Is , there is .svc file of the service, no "index" file for a wcf service.
[no name] 30-Jul-13 12:01pm
   
Either they have no idea what you are talking about or they may not allow hosting wcf services on their servers. The .svc file should be all you need.
ZurdoDev 30-Jul-13 12:54pm
   
It depends. You can host WCF in IIS, windows service, console app, etc. You need to post your config and explain how you are doing things.
Member 9568921 30-Jul-13 14:01pm
   
How I'm doing my working:

1. I've created a "WCF Service Library" name as "Collect Info".

2. I included the Service Reference of the WCF library on the WCF project. After that, I created another project of "WCF Project" and removed it's default IService.cs file and changed the mark up of the Service1.svc to point to the ServiceClass.cs of the Service Library.
Member 9568921 30-Jul-13 14:02pm
   
I can't seem to paste the config code. I'm quite new to this website, I believe there is a special format to paste the xml code.
ZurdoDev 30-Jul-13 14:05pm
   
When you paste you'll get a tooltip that pops up and you can choose to format it. Don't do it in a comment but use the Improve Question link.
Member 9568921 30-Jul-13 14:12pm
   
I've put the details. Please see and let me know. Thanks.
ZurdoDev 30-Jul-13 14:18pm
   
So you are hosting it through IIS at http://localhost/CollectInfoSvc/. So, what exactly is your question?
Member 9568921 30-Jul-13 14:22pm
   
Currently with this address I'm able to Host the service via Visual Studio's development server But I need to Host my service on my Windows Web Hosting domain. For that I just changed the "http://localhost/CollectInfoSvc/" address to "www.collect-info.com‏/TestWCF/" . But it didn't work for me.
ZurdoDev 30-Jul-13 14:25pm
   
Does www.collect-info.com‏/TestWCF/ exist? Do you get an error? Is the service running there?
Member 9568921 30-Jul-13 14:28pm
   
Yes, The folder Exists. I'm getting a 403 forbidden Error. Though I've asked my Web Hosting But they say that I've all the access. Can you tell me if I need other special permissions to Host a WCF service. any other requirements except for IIS ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900