Odd Remoting error - Security - BusinessPrincipal ? ?

Odd Remoting error - Security - BusinessPrincipal ? ?

Old forum URL: forums.lhotka.net/forums/t/440.aspx


brettswift posted on Wednesday, June 21, 2006

"C:\\Projects\\CSLA 2.0 projects\\CSLA 2.0\\Csla\\DataPortal\\Server\\DataPortal.cs:line 84"

My application is in inetpub/wwwroot/HTRemotingHost/   and so is  csla.dll, and my BO assemblies, so why would it be referencing this location?  Maybe its the .pdb  debug files that carry an old location reference?

The main question is this exception message when I try to make a  call to my BO's.  I'm not sure why it would be saying this, because my HTPrinciple Class is of type BusinessPrincipalBase

"  public class HTPrincipal : Csla.Security.BusinessPrincipalBase  "

ex.Message =
"Principal must be of type BusinessPrincipal, not System.Security.Principal.GenericPrincipal"



ex.StackTrace
"\r\nServer stack trace: \r\n   at Csla.Server.DataPortal.SetContext(DataPortalContext context) in C:\\Projects\\CSLA 2.0 projects\\CSLA 2.0\\Csla\\DataPortal\\Server\\DataPortal.cs:line 282\r\n   at Csla.Server.DataPortal.Fetch(Object criteria, DataPortalContext context) in C:\\Projects\\CSLA 2.0 projects\\CSLA 2.0\\Csla\\DataPortal\\Server\\DataPortal.cs:line 84\r\n   at Csla.Server.Hosts.RemotingPortal.Fetch(Object criteria, DataPortalContext context) in C:\\Projects\\CSLA 2.0 projects\\CSLA 2.0\\Csla\\DataPortal\\Hosts\\RemotingPortal.cs:line 36\r\n   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)\r\n   at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)\r\n   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMes
sage msg, Int32 methodPtr, Boolean fExecuteInContext)\r\n\r\nException rethrown at [0]: \r\n   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)\r\n   at Csla.Server.IDataPortalServer.Fetch(Object criteria, DataPortalContext context)\r\n   at Csla.DataPortalClient.RemotingProxy.Fetch(Object criteria, DataPortalContext context) in C:\\Projects\\CSLA 2.0 projects\\CSLA 2.0\\Csla\\DataPortal\\Client\\RemotingProxy.cs:line 100\r\n   at Csla.DataPortal.Fetch(Object criteria) in C:\\Projects\\CSLA 2.0 projects\\CSLA 2.0\\Csla\\DataPortal\\Client\\DataPortal.cs:line 166\r\n   at Csla.DataPortal.Fetch[T](Object criteria) in C:\\Projects\\CSLA 2.0 projects\\CSLA 2.0\\Csla\\DataPortal\\Client\\DataPortal.cs:line 138\r\n   at HorseTracker.Library.AnimalList.GetAnimalList() in C:\\Projects\\HorseTracker\\HorseTracker\\HorseTracker.Library\\AnimalList.cs:line 21\r\n   at HorseT
racker.WinGUI.AnimalsGUIInfo.GetChildren() in C:\\Projects\\HorseTracker\\HorseTracker\\HorseTrackerWin\\MetaObjects\\AnimalsGUIInfo.cs:line 48"

brettswift replied on Thursday, June 22, 2006

Well this is strange, I setup the Project Tracker application for remoting, and it gives me the identical error as above. 

Both applications work when set to a local data portal, and both give the same exception when set up for remoting!


 

RockfordLhotka replied on Thursday, June 22, 2006

Both your client and server config files need to have the same authentication setting (Csla). Having one side different (or not set at all) is the most common cause of this exception.

brettswift replied on Thursday, June 22, 2006

Thanks Rocky,

I didn't have the csla authentication mode set on my client - but I do now...
It seemed to get me somewhere, because I was getting a different error saying it couldn't connect to the server (which is a different issue, I even physically bypassed my router when using my url, so I know its not the firewall).

When I plug in localhost to the config of the remoting host , I get the same type error as above.

brettswift replied on Thursday, June 22, 2006

hmm.. well its a serialization exception.  "Input stream is not a valid binary format".  

I've checked my business objects to make sure they have the serializable attribute, as well as criteria classes..   maybe there's a common overlook here as well?  I know it has to be a simple configuration thing again...  

brettswift replied on Thursday, June 22, 2006

http://localhost/HorseTrackerRemHost/RemotingPortal.rem?wsdl

According to this post:  http://forums.lhotka.net/forums/thread/654.aspx

I should be able to tell more about if my data portal is working or not.  But I am getting this error.


System.IO.FileNotFoundException: Could not load file or assembly 'CSLA.Server.DataPortal' or one of its dependencies. The system cannot find the file specified. File name: 'CSLA.Server.DataPortal'


Its right there!  Its in the Bin directory.  I even tried pulling it out into the root  (HorseTrackerRemHost), rebuilding etc.   They were put there via referencing them in my empty web project,  with an appropriate config file.   I even tried deleting all of them, and putting them in there manually (CSLA.dll, horseTracker.Library.dll, and Csla.XmlSerializers.dll went with it.

still nothing.

what a pain in the butt this is!

RockfordLhotka replied on Thursday, June 22, 2006

Wait. It is looking for a file named Csla.Server.DataPortal? Are you running CSLA 1.x or 2.0? If 2.0, there's no such file, and so this would indicate that you have a typo in your config file where the type name and assembly name are reversed.
 
Rocky

brettswift replied on Thursday, June 22, 2006

Using 2.0, that wasn't in there originally, I must have copied an old 1.* config by accident, what a long day.

heres's my config, and the current errors. 

Config:
<?xml version="1.0"?>
<configuration>
    <system.runtime.remoting>
        <application>
            <service>
                <wellknown mode="SingleCall" objectUri="RemotingPortal.rem" type=" CSLA.Server.Hosts.RemotingPortal, Csla"/>
            </service>
            <channels>
                <channel ref="http">
                    <serverProviders>
                        <provider ref="wsdl"/>
                        <formatter ref="soap" typeFilterLevel="Full"/>
                        <formatter ref="binary" typeFilterLevel="Full"/>
                    </serverProviders>
                </channel>
            </channels>
        </application>
    </system.runtime.remoting>
    <appSettings>
        <add key="CslaAuthentication" value="Csla"/>
    </appSettings>
    <system.web>
        <compilation>
            <assemblies>
                <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
                <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation></system.web></configuration>





Error when Browsing to:  http://localhost/HorseTrackerRemHost/RemotingPortal.rem?wsdl

System.Runtime.Remoting.RemotingException: Cannot load type 'CSLA.Server.Hosts.RemotingPortal, Csla'.

and when I try to access it from my app, I get the serialization exception. "The Input stream is not a valid binary format"




brettswift replied on Thursday, June 22, 2006

Ok, that was dumb,   i had CSLA instead of Csla.   So, now I can see the xml wsdl when navigating to it in my browser, but... I'm right back where I started with the BusinessPrincipal exception!

I checked the appsettings, and they're there on the client and the remoting host (as you can see above in the appsettings section).


bcdennis replied on Friday, June 23, 2006

I'm having the EXACT same issues when I try to run any nunit tests from within VS.  Thinking I had royally screwed the pooch, I even reformatted my dev machine and re-installed everything. Viola, same problem.  I don't know what to do.  Using Csla 2.0.2.

guyroch replied on Friday, June 23, 2006

Try to do a logout before your first login, this should set the underlying thread.Principal to your Principal type instead of the default GenericPrincipal. It seems odd to do a logout first but give it a try anyway.

Remember, Csla doesn't care if you're authenticated or not, it just needs the right Principal/Indentity pair.

GuyRoch

brettswift replied on Sunday, June 25, 2006

I swear there were a couple posts lost on this thread.

Anyways, the logout sounds like a hack because you should be able to get remoting to work without logging in.. or maybe this is a quirk with a remoting host.   My error comes up if I log in or not, and if I do your suggested Logout then I get a dataportal_fetch error "object ref not set".

I think its one of two things - my .dlls aren't visible on my server, OR, there is something wrong with the serialization / deserialization in my code.  

Maybe someone could offer a checklist of things to go through in my code as far as serialization - I know all Business Objects need to be marked serializable...  anything else?  Anything NonSerializable?

This is the biggest headache I've had in a while.. i have to fix this!


guyroch replied on Sunday, June 25, 2006

Yep, server crash so a couple of posts might be lost in space

http://forums.lhotka.net/forums/thread/2280.aspx

brettswift replied on Tuesday, June 27, 2006

Because I'm not able to figure out this problem - and the people who have put the effort in to help me on this haven't solved my problems the way they solved theirs with remoting, I'd like to offer an invitation to anyone who thinks they would like to test my remoting setup to see if they get the same errors - and maybe we can clarify this.

So, if anyone would like, please reply to this thread - (I can respond quickly because I will be notified on my blackberry) - and I will send you a copy of my project to see if you can get it working.

This is a project I'm doing pro bono so source code is completely open, and you can modify / use my project as you wish - although it really isn't complex at all !


Hopefully someone has a spare half hour or so..   thanks to those who have helped so far!



guyroch replied on Tuesday, June 27, 2006

Send me your solution, I'll give it try when I can a chance.  I got my remoting to work with CSLA 2.0 a while back with no problems whatsoever.

Send to guyroch [no spam please] at gmail dot com.

brettswift replied on Tuesday, June 27, 2006

Hey

Thanks for the help

I will as soon as I recover my crashed pc lol. Perfect timing!

Computers hate me these days







Thanks,

Brett Swift
(403) 861-2552


-----Original Message-----
From: "guyroch"
Date: Tue, 27 Jun 2006 18:37:33
To:"brettswift@gmail.com"
Subject: Re: [CSLA .NET] RE: Odd Remoting error - Security - BusinessPrincipal ? ?

Send me your solution, I'll give it try when I can a chance.  I got my remoting to work with CSLA 2.0 a while back with no problems whatsoever.

Send to guyroch [no spam please] at gmail dot com.



brettswift replied on Wednesday, June 28, 2006

Thanks GuyRoch - huge help.  I knew it was just something stupid.... my config file -DB String in the client rather than the remoting host.  I thought I had tried that previously but there must have been a different error at that time - because it works now.

phew

guyroch replied on Wednesday, June 28, 2006

Brett, for the purpose of this thread and for the benefit of the entire CSLA community, I'm posting the steps I took to troubleshoot your GenericPrincipal issue your had with remoting in the hope that I might help somebody else in the future.

----- Start -----

I got it to work just fine Brett, I'm not getting any IPrincipal error
when logged in.

Here's waht I did once I created the database and added a few data rows.

(1) I mocked the DataPortal_Fetch of your HTIdentity so that I would
always log in

       public void DataPortal_Fetch(Criteria criteria)
       {
           _name = "BOB";
           _isAuthenticated = true;
           _roles.Add("Administrator");
       }

(2) I added a connection string to you wed.config

       <connectionStrings>
               <add name="HorseTracker"
                  connectionString="Data Source=(local);initial
catalog=HorseTracker;user id=sa;password=p1234567;Connect Timeout=120"
                  providerName="System.Data.SqlClient" />
               <add name="Security"
                  connectionString="Data Source=(local);initial
catalog=CjamSecurity;user id=sa;password=p1234567;Connect Timeout=120"
                  providerName="System.Data.SqlClient" />
       </connectionStrings>

(3) I create a virtual directory in IIS and had it pointed to the web
project and made sure the the http://.....?wsdl is working just fine.
It did.

(4) I fired up the app and clicked on "Expand All" button.  Sure
enough I got the GenericPrincipal error.  I was expecting this because
I wasn't loogin just yet.

(5) The clicked on login and typed in a user name and password.
Didn't really matter what Ityped in here because of step (1).

(6) Once logged in, I clicked the "Reload" button and then the "Expand
All" button again.

(7) Works like a charm, the animals were listed.

Hope this helps.  Let me know.

----- End -----

jspurlin replied on Tuesday, September 12, 2006

I could use some help here, too. I added the appropriate config section and Guy recommended, but I am still getting the file not found exception, and there is no Csla.Server.DataPortal.dll file.

There is a Csla.dll and the ProjectTracker.Library.dll, though.

I am just trying to get the sample project up and running.

guyroch replied on Tuesday, September 12, 2006

What's up Doc!

Send me you app.config file on your client and your web.config file on your remoting server and I'll see what I can do...

guyroch replied on Tuesday, September 12, 2006

BTW, Csla.DataPortal.Server is not a file, but rather a namespace in the Csla.dll assembly.

jspurlin replied on Tuesday, September 12, 2006

Guy, this may be part of the problem.  I am in the process of implementing CSLA with my place of work.  I am at home and on a single box.

I am new to physically distributed applications. My assumption was that I could build on my machine and test the various scenarios in advance before I sell the boss on the idea to purchase another server, though I am sure he is sold on the idea we will eventually need to.

Working at home, on one box, is there still a way to test the remoting (serialized as binary) and webservice (remoting, serialized as soap)?  Before I send you these files?

guyroch replied on Tuesday, September 12, 2006

You bet you can run w/ remoting on one box.

1) Create a web project and add the Csla.dll as a reference, and all of your BO dlls that you have created.  Call you web project MyRemotingTest

2) Add a web.config file into this web project and configure it properly... add the following in the <system.runtime.remoting> section.

  <system.runtime.remoting>
    <application>
      <service>
        <wellknown mode="SingleCall" objectUri="RemotingPortal.rem" type="Csla.Server.Hosts.RemotingPortal, Csla"/>
      </service>
      <channels>
        <channel ref="http">
          <serverProviders>
            <provider ref="wsdl"/>
            <formatter ref="soap" typeFilterLevel="Full"/>
            <formatter ref="binary" typeFilterLevel="Full"/>
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>

3) Go into IIS and create a virtual directory and call it MyRemotingTest and have it pointed to you web project .   If you have both the .Net framework 1.1 and 2.0 install you'll have to set your virtual directory to use 2.0 - it uses 1.1 by default.

4) Test the remoting works by typing the following in your browser.

http://localhost/MyRemoringTest/RemotingPortal.rem?wsdl

If remoting works, you should get something similar to this...

  <?xml version="1.0" encoding="UTF-8" ?>
- <definitions name="RemotingPortal" targetNamespace="http://schemas.microsoft.com/clr/nsassem/Csla.Server.Hosts/Csla%2C%20Version%3D2.0.3.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D93be5fdc093e4c30" xmlns="http://schemas.xmlsoap.org/wsdl/"

5) Now that you have confirmed that remoting works, create client app and add the Csla.dll as a reference, and all of your BO dlls that you have created.

6) Add an app.config file to you client app and add to following in the <appSettings> section.

  <appSettings>
    <add key="CslaAuthentication" value="Csla" />
    <add key="CslaDataPortalProxy" value="Csla.DataPortalClient.RemotingProxy, Csla"/>
    <add key="CslaDataPortalUrl" value="http://localhost/MyRemoringTest/RemotingPortal.rem"/>
  </appSettings>

7) VoilĂ , remoting should work.

jspurlin replied on Wednesday, September 13, 2006

I am trying to get this to work with the actual ProjectTracker sample, too.

I have the PTWin app working and ran into the same problem Brett did at login with the WebApp. I got the serialization error.

When I set up the web.config file with the ProjectTracker sample like this:

<appSettings>

<add key="CslaAuthentication" value="Csla"/>

<add key="CslaDataPortalProxy" value="Csla.DataPortalClient.RemotingProxy, Csla"/>

<add key="CslaDataPortalUrl" value="http://localhost/PTWebVB/RemotingPortal.rem"/>

<!--<add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WebServicesProxy, Csla"/>

<add key="CslaDataPortalUrl" value="http://localhost:3137/WebServicesHost/WebServicePortal.asmx"/>-->

<!-- <add key="CslaDataPortalProxy" value="EnterpriseServicesHost.EnterpriseServicesProxy, EnterpriseServicesHostvb"/> -->

</appSettings>

<connectionStrings>

<add name="PTracker" connectionString="Data Source=(local);Initial Catalog=PTracker;Integrated Security=True;" providerName="System.Data.SqlClient"/>

<add name="Security" connectionString="Data Source=(local);Initial Catalog=PSecurity;Integrated Security=True;" providerName="System.Data.SqlClient"/>

</connectionStrings>

<system.runtime.remoting>

<application>

<service>

<wellknown mode="SingleCall"

objectUri="RemotingPortal.rem"

type="CSLA.Server.Hosts.RemotingPortal, Csla" />

</service>

<channels>

<channel ref="http">

<serverProviders>

<provider ref="wsdl" />

<!-- TODO: comment the following two lines for .NET 1.0 -->

<formatter ref="soap" typeFilterLevel="Full" />

<formatter ref="binary" typeFilterLevel="Full" />

</serverProviders>

</channel>

</channels>

</application>

</system.runtime.remoting>

I get this error when I type http://localhost/PTWebVB/RemotingHost.rem?wsdl

System.Runtime.Remoting.RemotingException: Cannot load type 'CSLA.Server.Hosts.RemotingPortal, Csla'.
   at System.Runtime.Remoting.RemotingConfigHandler.RemotingConfigInfo.LoadType(String typeName, String assemblyName)
   at System.Runtime.Remoting.RemotingConfigHandler.RemotingConfigInfo.GetServerTypeForUri(String URI)
   at System.Runtime.Remoting.RemotingConfigHandler.GetServerTypeForUri(String URI)
   at System.Runtime.Remoting.RemotingServices.GetServerTypeForUri(String URI)
   at System.Runtime.Remoting.Channels.Http.HttpRemotingHandler.CanServiceRequest(HttpContext context)
   at System.Runtime.Remoting.Channels.Http.HttpRemotingHandler.InternalProcessRequest(HttpContext context)

jspurlin replied on Wednesday, September 13, 2006

I got it!

<wellknown mode="SingleCall"

objectUri="RemotingPortal.rem"

type="CSLA.Server.Hosts.RemotingPortal, Csla" />

has to be changed to

<wellknown mode="SingleCall"

objectUri="RemotingPortal.rem"

type="Csla.Server.Hosts.RemotingPortal, Csla" />

guyroch replied on Wednesday, September 13, 2006

Glad to see you got it to work.

Yeah, I too find it somewhat stupid that is case sensitive.

sune42 replied on Wednesday, September 27, 2006

I also got this error "Principal must be of type BusinessPrincipal, not System.Security.Principal.GenericPrincipal" today and my bug was that I accidently called my CSLA business objects before I did the authentication/login operation.

After I fixed it so that I logged in first, the error went away.

//Andy




Copyright (c) Marimer LLC