ServiceStack deployment in IIS (404 exception)

278 views
Skip to first unread message

panks

unread,
Jan 12, 2014, 4:43:31 PM1/12/14
to servic...@googlegroups.com

I have looked a lot into ServiceStack question in Stackoverflow and really running out of options. Spent a lot of time and tried a lot of options but not being able to run my ServiceStack services in IIS. I have a virtual directory under default website named as api and the physical location pointing that to is bin directory of servicestack assemblies. Just for testing I have put an index.htm in the bin folder and when on server I navigate to : localhost/api , I get the contents of index.htm from bin folder. However as you see in below code , my client invocation of Sericestack service via JSONServiceClient results in 404 exception. I am not sure what am I missing. Thanks much in advance

PS: have posted on SO but didnt receive a response.

Here is my code:

Service Stack version: 3.9.69.0, IIS version 8.0


using System.Configuration;
        using ServiceStack.OrmLite;
        using ServiceStack.OrmLite.SqlServer;

        //  logging
        using ServiceStack.Logging;

    //  Service Interface project
    public class xxxService   : Service
    {
    public List<xxxResponse> Get(xxxQuery xxxQuery) 
    }



    [Route("/xxxFeature/{xxxSerialNo}/{xxxVersion}")]
    public class xxxQuery : IReturn<List<xxxResponse>>
    {
        public string xxxSerialNo { get; set; }
        public string xxxVersion { get; set; }
    public string xxxId { get; set; }
        public string xxxName { get; set; }
    }


    public class xxxResponse
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Version { get; set; }
        public string Size { get; set; }
        public ResponseStatus ResponseStatus { get; set; }
    }


Web.config
--
<?xml version="1.0" encoding="utf-8"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

  <configSections>

  </configSections>


  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <location path="api"> 
    <system.web>
      <httpHandlers>
        <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
      </httpHandlers>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>

    <!-- Required for IIS7 -->
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
      <validation validateIntegratedModeConfiguration="false" />
      <handlers>
        <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
      </handlers>
    </system.webServer>
  </location>

    <system.webServer>
        <directoryBrowse enabled="false" />
    </system.webServer>
</configuration>

Global.asax.cs
----
    public class Global : System.Web.HttpApplication
    {

        public class xxxServiceAppHost : AppHostBase
        {
            public xxxServiceAppHost()
                : base("xxx Services", typeof(xxxService).Assembly)
            {
                #region "Log4Net"
                //  log4net.Util.LogLog.InternalDebugging = true;
                ServiceStack.Logging.LogManager.LogFactory = new Log4NetFactory(true);
                Log4NetUtils.ConfigureLog4Net(ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["ServerDB"]].ConnectionString);
                #endregion "Log4Net"
            }

            public override void Configure(Funq.Container container)
            {
                container.Register<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["ServerDB"]].ConnectionString, SqlServerDialect.Provider));
                SetConfig(new EndpointHostConfig { ServiceStackHandlerFactoryPath = "api" });
            }


        }

        //  To avoid conflicts with ASP.NET MVC add ignore rule in Global.asax RegisterRoutes method e.g: routes.IgnoreRoute ("api/{*pathInfo}");

        public void RegisterRoutes(RouteCollection routes)
        {
            routes.Ignore("api/{*pathInfo}");
        }


        protected void Application_Start(object sender, EventArgs e)
        {
            new xxxServiceAppHost().Init();
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }

    // client invocation

                try
                {
                    xxxServiceClient = new JsonServiceClient("http://111.16.11.111/api/xxxService");
                    List<xxxResponse> xxxResponses = xxxServiceClient.Get(new xxxQuery { xxxSerialNo = "22222", xxxVersion = "0.0" });

                }

                catch (WebServiceException excp)
                {
                    throw excp;
                }

Demis Bellot

unread,
Jan 12, 2014, 10:05:32 PM1/12/14
to servic...@googlegroups.com
Only the base url should be used in the service clients, e.g:

xxxServiceClient = new JsonServiceClient("http://111.16.11.111/api");


--
You received this message because you are subscribed to the Google Groups "ServiceStack .NET Open Source REST Web Services Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to servicestack...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

panks

unread,
Jan 13, 2014, 12:05:59 AM1/13/14
to servic...@googlegroups.com
Thanks for your response mythz. Actually I had tried with base url before and it ends up with same result i.e. 404 exception. It looks to me there is some configuration issue. Earlier I was trying to create a separate application and virtual dir. inside IIS , however to simplify things I now have just created a virtual directory named api (which is what ServiceStack has worked on from earlier versions; at least thats what I gathered from SO posts who had deployment issue). I can navigate to http://111.16.11.111/api remotely and can see index. htm contents but some how these requests get 404. I also dont get any metadata results through servicestack. 

Wayne Douglas

unread,
Jan 13, 2014, 2:34:52 AM1/13/14
to servic...@googlegroups.com, servic...@googlegroups.com
Because you have a vdir of /api, depending on how you've set up servicestack, you might even have ended up with a base URL of 
http://111.16.11.11/api/api

I can't read the code in your email as it's all jumbled for me but I'd suspect this could be a reason for your 404?
—
Sent from Mailbox for iPhone

panks

unread,
Jan 13, 2014, 3:19:56 AM1/13/14
to servic...@googlegroups.com
Thanks for your response Wayne. I tried but to no avail. The link on stackoverflow for my post is : http://stackoverflow.com/q/21056042/179400
Code should be much readable there.

Allen Newton

unread,
Jan 21, 2014, 9:51:39 PM1/21/14
to servic...@googlegroups.com
Posted a response on stackoverflow.  Hope that helps! :)
Reply all
Reply to author
Forward
0 new messages