locked
wcf service doesn't work in deployment (can't load factory type) RRS feed

  • Question

  • I am getting an issue trying to access a WCF service hosted by IIS.
    I need to use a factory, so in the .svc file I have specified

    <%@
    ServiceHost Language="C#" Debug="true"
    Service="SilverlightApplication4Web.Service1"
    Factory="SilverlightApplication4Web.Service1HostFactory"
    CodeBehind="Service1.svc.cs
    %>

    however I am getting the following error when I browse to the .svc file on the server: (http://taylor.hostinguk.org/Silverlight/Service1.svc)


    Parser Error Message: The CLR Type 'SilverlightApplication4Web.Service1HostFactory' could not be loaded during service compilation. Verify that this type is either defined in a source file located in the application's \App_Code directory, contained in a compiled assembly located in the application's \bin directory, or present in an assembly installed in the Global Assembly Cache. Note that the type name is case-sensitive and that the directories such as \App_Code and \bin must be located in the application's root directory and cannot be nested in subdirectories.

    I've checked and double-checked the name of Service1HostFactory for typos and everything is correct, besides it works in debug - it is only when deploying using VS 2008's "Build -> publish" that I get this error.

    I don't think it's an issue with execute permissions on the web server as all the DLLs have got read and execute permissions and another normal web app on the same host works fine.

    any ideas what might be the problem?

     

    Thursday, August 28, 2008 6:15 AM

Answers

  •  i don't think that's it, 'cos it can't instantiate it at all - but I got the same issue with a web service (.asmx) until I created a new one from scratch and deployed it to a brand new virtual directory, which I'd just created - so I think the issue must have been with the actual directory i was deploying it to before not being configured a an ASP.NET application correctly.

     

    Friday, August 29, 2008 4:23 AM
  •  no, i'm still getting it with a wcf service though. What class is 'CustomServiceHost'?

    Friday, August 29, 2008 5:08 AM

All replies

  •  Hi,

    Can you show the declaration of  the factory?

    Thursday, August 28, 2008 8:01 AM
  •  yes, it's:

    namespace SilverlightApplication4Web
    {
        // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config.
        public class Service1 : IService1
        {
            public void DoWork()
            {
            }

            public string GetData(int i)
            {
                return "You entered " + i + "!";
            }
        }

        public class Service1HostFactory : ServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            {
                return new ServiceHost(serviceType, baseAddresses[0]);
            }
        }

    }
     

    Thursday, August 28, 2008 8:21 AM
  • Try to use something like this:

    public class MyServiceHostFactory : ServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            return new CustomServiceHost(serviceType, new Uri("http://localhost/.../LogicLayer.svc"));
        }
    }

    Thursday, August 28, 2008 4:13 PM
  •  i don't think that's it, 'cos it can't instantiate it at all - but I got the same issue with a web service (.asmx) until I created a new one from scratch and deployed it to a brand new virtual directory, which I'd just created - so I think the issue must have been with the actual directory i was deploying it to before not being configured a an ASP.NET application correctly.

     

    Friday, August 29, 2008 4:23 AM
  •  no, i'm still getting it with a wcf service though. What class is 'CustomServiceHost'?

    Friday, August 29, 2008 5:08 AM
  •  no sorry i've got it working now.

    Cheers!

     still curious as to what you mean by ""Custom"" ServiceHost though.

    Friday, August 29, 2008 5:14 AM
  • Sorry,

    public class CustomServiceHost : ServiceHost
    {
        public CustomServiceHost(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses) { }

        protected override void ApplyConfiguration()
        {
            base.ApplyConfiguration();
        }
    }

     
    Friday, August 29, 2008 5:15 AM