"Remote server error: (403) forbidden" after using the Activator.GetObject() method.

Last post 11-21-2006 12:03 PM by Caddre. 3 replies.

Sort Posts:

  • "Remote server error: (403) forbidden" after using the Activator.GetObject() method.

    11-20-2006, 1:54 PM

    Hello!

    I'm developing an aspnet remoting (using C#) for the first time and facing some unexpected issues.
    There are four projects in my solution (VS2005, framework 2.0)

    A business layer (classlibrary)

    An interface component - to interact with the business layer (classlibrary)

    A WebApplication - where I've placed my aspx that interacts with the interface component.

    A console application (to open the remoting channel).

    Here is what I'm doing, respectively:

    --- 

    using InterfaceRemoting;

    namespace Negocio
    {
        public class Client : MarshalByRefObject, InterfaceRemoting.IClient
        {
            public Client()
            {
            }

            public DataTable getData()
            {
                SqlConnection conn      = new SqlConnection();
                SqlCommand cmd          = new SqlCommand();
                SqlDataAdapter da       = new SqlDataAdapter();
                DataTable dt            = new DataTable();
                conn.ConnectionString   = "The ConnectionString";
                cmd.Connection          = conn;
                cmd.CommandText         = "The CommandText";
                da.SelectCommand        = cmd;
                da.Fill(dt);

                conn.Dispose();
                cmd.Dispose();
                da.Dispose();

                return dt;
            }
        }
    }

    ------------------------------------------------------

    using System;
    using System.Data;

    namespace InterfaceRemoting
    {
       public interface ICliente
       {
         DataTable getData();
       }
    }

    --------------------------------------------------------

    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels.Http;

    using DataDynamics.ActiveReports;
    using DataDynamics.ActiveReports.Web;
    using DataDynamics.ActiveReports.Document;

    using InterfaceRemoting;
    using Reports;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            IClient cli = (IClient)Activator.GetObject(typeof(IClient), "
    http://localhost/RMTReport/Default.aspx");
            RptTest reportDesign    = new RptTest();
            reportDesign.DataSource = cli.getData();
            ReportViewer.Report     = reportDesign;
        }
    }

    ------------------------------------------------------------------------------------------------------------------------------------------------------------

    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting.Channels.Http;

    using Negocio;

    namespace Server
    {
        class Program
        {
            [STAThread]
            static void Main(string[] args)
            {
                ChannelServices.RegisterChannel(new HttpServerChannel(),true);
                WellKnownServiceTypeEntry wkste = new WellKnownServiceTypeEntry(typeof(Client), "Negocio", WellKnownObjectMode.Singleton);
                RemotingConfiguration.RegisterWellKnownServiceType(wkste);

                Console.WriteLine("Criou Remoting");
                Console.ReadLine();  
            }
        }
    }

    Well, my doubts are highlighted in red...I mean what is the connection between the ObjectURI parameter of the wkste object and the URL parameter of the Activator.GetObject method?

    Could it be the source of the (403) forbidden exception message I got when the reportDesign.DataSource = cli.getData() statement is performed?

    Is there any IIS configuration that can be causing that excepting too?

    I've also changed some properties in the "Set Startup Projects" (seted the console and web application to start together)...

    With this scenario in mind, what do you think I'm doing wrong to cause the exception?

  • Re: "Remote server error: (403) forbidden" after using the Activator.GetObject() method.

    11-20-2006, 7:59 PM
    • All-Star
      26,551 point All-Star
    • Caddre
    • Member since 06-23-2003, 9:53 AM
    • Indy
    • Posts 5,308

    The System.Activator permissions requirements is covered in the docs.  Hope this helps.

    (You must have sufficient permission to search for and call a constructor, otherwise an exception is thrown. By default, only public constructors are considered during the search for a constructor. If no constructor or default constructor can be found, an exception is thrown.)

    http://msdn2.microsoft.com/en-us/library/system.activator.aspx

    Kind regards,
    Gift Peddie
  • Re: "Remote server error: (403) forbidden" after using the Activator.GetObject() method.

    11-21-2006, 11:44 AM

    Well,

     My englsih is not technically very good, so it takes some time to understand what is explained in english.

     Searching the web I've found many examples about .Net Remoting and among them I've noticied a detail: The soap extension added to the stringURI and to the stringURL parameters (WellKnownServiceTypeEntry and Activator.GetObject method respectively).

     WellKnownServiceTypeEntry wkste = new WellKnownServiceTypeEntry(typeof(Client), "Negocio.soap", WellKnownObjectMode.Singleton);

    IClient cli = (IClient)Activator.GetObject(typeof(IClient),"http://localhost:1234/Negocio.soap");

     The application worked out fine with those alterations. But, I did not realize why yet...any idea?

  • Re: "Remote server error: (403) forbidden" after using the Activator.GetObject() method.

    11-21-2006, 12:03 PM
    • All-Star
      26,551 point All-Star
    • Caddre
    • Member since 06-23-2003, 9:53 AM
    • Indy
    • Posts 5,308

     


      IClient cli = (IClient)Activator.GetObject(typeof(IClient), "http://localhost/RMTReport/Default.aspx");

    IClient cli = (IClient)Activator.GetObject(typeof(IClient),"http://localhost:1234/Negocio.soap");

    Your original code is an Asp.net page, your new code is connecting to Web service, again it is covered in the docs, so spend time with the docs for all the related info before looking for code.

    http://msdn2.microsoft.com/en-us/library/0315hz94.aspx

    http://msdn2.microsoft.com/en-us/library/system.security.permissions.reflectionpermission.aspx

     

    Kind regards,
    Gift Peddie
Page 1 of 1 (4 items)