none
WCF service not working with Authority RRS feed

  • Question

  • I am having a problem using WCF from a javascript post to different authorities on a website.  The website has three different authorities below all in that order.

    d8926526.c101.cvmediaonline.com = 0

    www.valleyvikings.net = 1

    valleyvikings.net = 2

    My .svc file looks like this

    <%@ ServiceHost Language="C#" Debug="false" Service="AdminServices" Factory="BaseHostFactory"
        CodeBehind="~/App_Code/AdminServices.cs" %>

    Now if I run it directly without having a Factory class attached to it, it gives me this error.

    This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.
    Parameter name: item

    So I fixed this issue using a Factory class attached to the service.

    AdminService.svc

    <%@ ServiceHost Language="C#" Debug="false" Service="AdminServices" Factory="BaseHostFactory"
        CodeBehind="~/App_Code/AdminServices.cs" %>

    BaseHostFactory.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ServiceModel.Activation;
    using System.ServiceModel;


    public class BaseHostFactory : ServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            BaseHost customServiceHost = new BaseHost(serviceType, baseAddresses[1]);
            return customServiceHost;
        }
    }

    public class BaseHost : ServiceHost
    {
        public BaseHost(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        { }
        protected override void ApplyConfiguration()
        {
            base.ApplyConfiguration();
        }
    }

    Now I pick 1 to use www.valleyvikings.net and it works with www.valleyvikings.net/adminservices.svc, but if I go to valleyvikings.net/adminservices.svc I get a 404 error.  Any clue on what to do?  Below is my web.config file.

     <system.serviceModel>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
            <behaviors>
                <endpointBehaviors>
                    <behavior name="AdminServicesBehavior">
                        <webHttp />
                    </behavior>
                </endpointBehaviors>
            </behaviors>
            <services>
                <service name="AdminServices">
                    <endpoint behaviorConfiguration="AdminServicesBehavior" binding="webHttpBinding"
                     contract="IAdminServices" />
                </service>
            </services>
        </system.serviceModel>


     

     



    Mike Flynn
    Friday, January 23, 2009 9:58 PM