In order to have two-way communication from the server to the client, the client activates a ServerObject, then passes in its own ClientObject (which is also a MarshalByRefObject) the server uses the ClientObject to talk back to the client:
var lsClient = new ClientObject();
var lsServer = (ServerObject)Activator.GetObject(typeof(ServerObject), url);
lsServer.attach(lsClient);
When the attach method is called, the server takes the ClientObject and stores it in a List:
public void attach(ClientObject client) {
clientList.Add(client);
}
The server can then call a method on the ClientObject called "SendMessage" to communicate to each client in its list:
foreach(var c in clientList) {
c.SendMessage("Hello");
}
This works great until a client is encountered that has disconnected. In this case, an error is thrown about the client refusing the connection. I can catch the error, but the problem is I cannot remove the reference to the ClientObject from the server's List. The following re-throws the "connection refused" exception anytime a client has been disconnected:
clientList.Remove(badClient);
So a couple of questions:
1- Is there a way to detect the connection state of a client without having to catch an error?
2- When I do detect a client that has disconnected, why does the attempt to remove the object from the server's list appear to "communicate" with the client (thus causing the exception to be thrown again?)
EDIT
As Patrick pointed out below, doing a Remove from a list causes the List to iterate my objects and do a comparison on them (calling .Equals) - this is what caused my ClientObject to attempt to communicate again and thus throw the exception. To resolve it, I instead changed the List to a dictionary keyed off a unique ID supplied by my Client at the time of attaching to the server. Then I used that unique ID to remove the client. I never did find a direct way for determining if a client had disconnected other than catching the error.
I have a question, much liket this unanswered one. I'm trying to work with the entity framework, and having a tough time getting my foreign tables to update. I have something basically like this in the DB:
Incident (table):
-ID -other fields
Responses (table):
-FK:Incident.ID -other fields
And and entities that match:
Incident (entity) -ID -Other fields -Responses (EntityCollection of Responses via navigation property)
Each Incident can have 0 or more responses.
In my Webpage, I have a form to allow the user to enter all the details of an Incident, including a list of responses. I can add everything to the database when a new Incident is created, however I'm having difficulty with editing the Incident.
When the page loads for edit, I populate the form and then store the responses in the viewstate. When the user changes the list of responses (adds one, deletes one or edits one). I store this back into the viewstate. Then when the user clicks the save button, I'd like to save the changes to the Incident and the Responses back to the DB. I cannot figure out how to get the responses from the detached viewstate into the Incident object so that they can be updated together.
Currently when the user clicks save, I'm getting the Incident to edit from the db, making changes to the Incident's fields and then saving it back to the DB. However I can't figure out how to have the detached list of responses from the viewstate attach to the Incident. I have tried the following without success:
Clearning the Incident.Responses collection and adding the ones from the viewstate back in:
Incident.Responses.Clear() for each objResponse in Viewstate("Responses") Incident.Responses.add(objResponse) next Creating an EntityCollection from my list and then assiging that to the Incident.Responses Incident.Responses = EntityCollectionFromViewstateList Iterating through the responses in Incident.Response and assigning the corresponding object from viewstate: for each ObjResponse in Incident.Responses objResponse = objCorrespondingModifedResonseFromViewState Next
These all fail, I'd like to be able to merge the changes into the Inicdent object so that when the BLL calls SaveChanges on the changes to both the Incident and Responses will happen at the same time.
In the project I'm working on I have got a list List<Item> with objects that Is saved in a session. Session.Add("SessionName", List);
In the Controller I build a viewModel with the data from this session
[Code]....
and in my View I loop trough the list of Items and make a form for all of them to be able to remove the item.
[Code]....
When the post from the submit button is handeld the item is removed from the array and post back exactly the same viewModel (with 1 item less in the itemList).
return View("view.ascx", viewModel);
When the post is handled and the view has reloaded the value's of the html.Hidden and Html.Textbox are the value's of the removed item. The value of the html.Encode is the correct value. When i reload the page the correct values are in the fields. Both times i build the viewModel the exact same way.
<p>Hi</p> <p>I'm a newbie in MVC but a veteran web forms developer. I really like the idea of strongly typed views but what if I have multiple objects to pass to my razor view. Would I then NOT use strongly typed views and just use the ViewBag?</p>
since asp.net contains multiple threads that are executing at the same time.so if 2 threads access an object (simple or complex) that i got from the the asp.net httpcontext Cache.can't this lead to state problems on that object if these 2 theads tried to modify/read it at the same time?so what kind of precautions should i implement?for example i am thinking maybe locking the object while working with it? (wont this cause performance problems?)or maybe when i retrieve some object from the cache i should create a copy from it? or maybe i dont need to worry about this issue at all?
I have a shared object through net remoting. The problem is that this object has some EntitySet and EntityRef attributes. When I try to run the program I get an exception telling me that EntitySet is not marked as Serializable. If I mark it as Serializable everything seems to be ok, but when I try to access from outsied to the attribute represented by the EntitySet, I am not able to use it.
BTW, Does anyone know how change the default binary serialization of tcp channel?
I'm building a Remoting Demo, and here's my scenario:
There are 4 projects:
ServicedCOM: This project I've built a ServicedComponent, this component using for access data from database.
RemoteLoader: I using this to load ServicedCOM to RemotingServer.
RemotingServer: This is an console application, and this application can be running from another computer.
WebApp: Client, this is inteface using for End User.
and my results: I can access and retrieve data with function is called SpeakHello (test function), but I cannot do the same thing to get sectors using this model, I think I'm doing something wrong. and here's my code snippet:
1. I have a ServicedCOM and a function to get Sectors is called GetSectors (I test OK)
disconnected mode and transaction.it's give to me ERROR message
Quote.ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized PHP Code: da.InsertCommand = cb.GetInsertCommand
my code is:
PHP Code: Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("DBCon").ConnectionString) Dim cmd As New SqlCommand("insert into Customer (customer_id, customer_name, note) values (@cid, @cname, @note)", con) Dim da As New SqlDataAdapter("select * from CustomerPhone", con)
I'm so excited about the webmatrix, because it makes all the works to be easier than ever before, so I make a try, but I met a problem when I deployed the project membership db to remoting host (I chose the cytanium.com), and I had deployed the project files and another database sucessfully, only the membership related database failed, the error message is below:
[Code]....
I thought that the problem source is about the collation of the database, so I change my database collation from "Chinese_PRC_CI_AS" to "SQL_Latin1_General_CP1_CI_AS", but the problem is the same, I had search a lot of articles, but I didn't find a way to resolve this issue.
When using .net remoting, does the server limit incoming client remoting calls?
I find a particular remoting call (during ASP.NET page rendering) to take from 200ms to 1500ms. While the underlying data call is only 50ms. Factoring in remoting overhead of 150ms per call, the only difference between the two cases is that the latter scenario has about a dozen more parallel remoting calls in progress. So my guess is that when too many remoting calls are happening, some will get queued up? I also doubt system resource is the cause of the delay because it is not nearly saturated.
Searching MSDN, I find the below:
http://msdn.microsoft.com/en-us/library/ms973907.aspx clientConnectionLimit: specifies how many connections can be simultaneously opened to a given server. The default is 2. This is exactly the same as the connection limit on ServicePoint in the net classes.
That seems awfully low to me and if were the case, my app's performance would have been much worse. Can someone confirm if there is indeed a connection limit or some other throttling in .net remoting?
The DataSet is a disconnected data object. Once the DataSet has been filled, the connection can be closed and the DataSet's contents can still be examined and manipulated.What does manipulated mean ? If possible, then please give me example(s) for manipulated.
I have designed program to display live events/content(like online orders in shop) at different location. Now case is, suppose Some of Clients putting order for material and suddenly Internet gets disconnect.So what I am looking for, in this case, I want to show some default text/images to End user who is trying to put orders. I am ready to design to Desktop Application to do this, but I need inputs on how to achieve this at User end?
I implemented a chat using the COMET "way" described in this article: http://www.codeproject.com/KB/aspnet/CometAsync.aspx
In this example, the client connects for 5 seconds every time. I wanted to hold the client longer, for about 10 minutes.
My problem is - how to detect if the client disconnected during those 10 minutes? I tried using Response.IsClientConnected but it returns true even if I close the client. There must by some inidicator since the socket gets disconnected if I close the client.
have some Objects, lets say Employee and Role defined as below and I have defined relationships in my database that gives me a list of objects say employees and thanks to my framework each employee object also has a Role object linked via the RoleIDID, UserName, Password, Email, RoleIDRoleID, RoleNameSo in code I can do something like this
I know how to bind a simple objects to a dropdown list. However I am having problems binding my objects which contains sub objects to the control.i.e. with simple object i just do ddl.DataValueField = "myproperty" with my objects they contains sub objects which i want to bind. I have tried ddl.DataValueField = "sub-object.myproperty" which doesnt work.
firstly a static class only ever exists once and is not an instance. Any static members (ie static int NoOfPeople;) is stored in one place and is shared between all sessions (like the old global variables). Now static methods is where i'm not 100% sure. If I have a static method that doesn't use any other static members could this cause inconstant results, example (this is a fairly pointless method but just a quick example of the top of my head)
[Code]....
So in this example if two sessions (or threads) were to call this at the same time - would they both get back the expected results, because the method only uses private data (a, b and totalToReturn).Im sure this sounds a little simple but I will be using static methods to build user objects and various other objects that there will have to be a 100% garentee that the objects will not get mixed up between sessions and the wrong things return to the user.
I'm working on a project in which we have a database, data layer (entity framework), business layer and web/UI layer.I want to use ASP.NET Dynamic Data for the web layer, but don't want it to access the data layer or database, as I want it to be purely running off business logic, and not directly accessing the data.However, it appears that Dynamic Data only allows Linq-to-SQL or entity framework data sources to be used.Has anyone used it with business-layer objects instead?
I need to filter the "Client Disconnected" error below in my global.asax file. Does anyone know what kind of exception it is so that if it matches i can do extra processing? ---------------------------------------------
Lets say I am doing a shoping cart. I authenticate the user with a session variable.For example:
If(Request.IsAuthenticated) // Here I want to add to the shoping cart. // Can I do the following Session["Cart"] = "Washing Machine"; Now will this Session["Cart"] value which is washing machine here be unique to diff customers?
I am very new to ASP.NET, and I understand this is very nooby, but I can't figure it out myself!
I'm trying to align objects on my master page. What I mean is I have the header banner, the footer banner, and a navigation menu in the middle. Now between the navigation menu bar and the footer banner, I have a shoutbox. I want to align this shoutbox to the right side of the page, so that it is even with the edge of the navigation menu bar and footer. The width of those is 1100px. I'm using visual studio 2008.
Have a C# application. When I look in the project folder I see an .exe in bin/debug folder, when I click it executes the application fine. I also see the same .exe in obj/debug folder, when I click it executes but gives me error. What is the difference between these 2 objects and why do I have 2 of them?
Currently i am having a list like List<Tickets> allTickets.I need to select in the same list some corresponding info about the ticket writer like List<Ticket, aspnet_User>.