.NET Framework Developer Center > .NET Development Forums > Windows Communication Foundation > Custom ServiceHostFactory Only Returns HTTPS BaseAddress
Ask a questionAsk a question
 

Proposed AnswerCustom ServiceHostFactory Only Returns HTTPS BaseAddress

  • Saturday, January 24, 2009 2:19 AMConcolor Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    Since my hosting provider uses a shared hosting environment (GoDaddy), I need to create a custom ServiceHostFactory object that overrides the CreateServiceHost function (as described here).  Before trying to make the WCF service work at GoDaddy, I am testing it locally on IIS v5 (standard install that comes with WinXP Professional with .NET v3.5).  The problem I have is that when IIS calls my override function CreateServiceHost, it only returns a HTTPS baseAddress.  I need just a plain HTTP baseAddress and don't understand why HTTPS is being returned by IIS.  I only have the default website configured on port 80/TCP.  Below is the code:

    Backend code file (.cs)

    namespace Concolor.Net.Services  
    {  
        [ServiceContract]  
        public interface IPhoneHomeService  
        {  
            [OperationContract]  
            void PostIp(string id);  
        }  
     
        public class PhoneHomeService : IPhoneHomeService  
        {  
            public void PostIp(string id)  
            {  
                //Do work  
            }  
        }  
     
        public class GodaddyServiceFactory : ServiceHostFactory  
        {  
            protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)  
            {  
                if (baseAddresses.Length > 1)  
                    return new ServiceHost(serviceType, baseAddresses[1]);  
                else 
                    return new ServiceHost(serviceType, baseAddresses[0]);  
            }  
        }  

    web.config

    <?xml version="1.0" encoding="utf-8"?>  
     
    <configuration> 
      <system.web> 
        <compilation> 
          <buildProviders> 
            <add extension=".svc" type="System.ServiceModel.Activation.ServiceBuildProvider, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
          </buildProviders> 
        </compilation> 
      </system.web> 
     
     
      <system.serviceModel> 
     
        <services> 
          <service name="Concolor.Net.Services.PhoneHomeService" behaviorConfiguration="PhoneHomeServiceBehaviors">  
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="InsecureBinding" contract="Concolor.Net.Services.IPhoneHomeService" /> 
          </service> 
        </services> 
       
        <behaviors> 
          <serviceBehaviors> 
            <behavior name="PhoneHomeServiceBehaviors">  
              <serviceMetadata httpGetEnabled="true"/>  
              <serviceDebug includeExceptionDetailInFaults="true"/>  
            </behavior> 
          </serviceBehaviors> 
        </behaviors> 
     
        <bindings> 
          <wsHttpBinding> 
            <binding name="InsecureBinding">  
              <security mode="None"/>  
            </binding> 
          </wsHttpBinding> 
        </bindings> 
          
      </system.serviceModel> 
    </configuration> 

    Service file (.svc)

    <%@ ServiceHost Language="C#" Debug="true" Service="Concolor.Net.Services.PhoneHomeService" Factory="Concolor.Net.Services.GodaddyServiceFactory"%> 

     

    Now if I take out the Factory="Concolor.Net.Services.GodaddyServiceFactory" attribute out of the .svc file to use just the standard ServiceHostFactory, it will return a HTTP baseAddress.  Use my custom ServiceHostFactory and it will only return a HTTPS baseAddress.

    Am I missing a configuration setting in my custom override of CreateServiceHost?  I have searched extensively for a solution, but have be unable to find fix.  I am still very new to WCF, so I appologize if this is a basic mistake.  Any help would be greatly appreciated.

    • Edited byConcolor Saturday, January 24, 2009 2:20 AMSyntax correction.
    •  

All Replies

  • Friday, August 21, 2009 8:49 PMSuman Chakrabarti [MSFT] Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed AnswerHas Code
    I think you're missing a base address list for that code snippet you've got.

    Why not add some base addresses into your <service> tag:

    <service ...>
      <endpoint ... />
      <host>
        <baseAddresses>
          <add baseAddress="http://myhost/service1.svc" />
          <!-- comment this one out when you want http: -->
          <add baseAddress="https://myhost/service1.svc" />
        </baseAddresses>
      </host>
    </service>
    

    Suman Chakrabarti [MSFT]