简体   繁体   中英

Is there a way to make in WCF a datamember of datacontract as a reference to an instance of class in server?

I am moving .NET Remoting solution to WCF. There are windows form client and WCF application server in session mode running as windows service and a layer of interaction application server and WCF core singleton server running as windows service too. The structure of data consist of about 20 middle weight classes for core and application server with mostly composition relationship and with corresponding interfaces. An interaction of a client and application server in .NET Remoting is provided by references to interfaces (proxies) on client to objects in server. That is working very well using full features of OOP. For example a Remoting request:

IDTGroupUser aDTGroupUser = addGroupUser( group, user, requestor);

Server side:

public IDTGroupUser addGroupUser(IDTGroup group, IDTUser user, 

IDTGroupUser Requestor)
    {
        if (Requestor.User.IsSuperUser || Requestor.Group.IsAdmin)
        {
            DTGroupUser gu = new DTGroupUser(group, user, Requestor);
            ISingletonSpace.groupUsers.Add(gu);
            return gu;
        }
        else return null;
    }

Now in WCF there is no object oriented approach. So far I am trying to use server object's ID on client side to link to server objects. If client need something from server then

client sending with each request one additional parameter - ID and on the server side first is searched by ID that object and then

performed needed operation. But this looks like a big bottleneck. WCF request:

int aDTGroupUser addGroupUser( gID, uID, requestorID);

Server side (where IDTUser, IDTGroup, IDTGroupUser and ISingletonSpace are endpoints):

public int addGroupUser( uint gID, uint uID, uint requestorID)
{
    if (IDTUser.UserIsSuperUser(uID) || IDTGroup.GroupIsAdmin(gID))      // 2 searching
    {
        uint guID = IDTGroupUser.createGroupUser(gID, uID, requestorID); // 3 searching
        ISingletonSpace.groupUsersAdd(guID);                             // 1 searching
        return guID;
    }
    else return -1;
}

How to organize interaction between client and application server without searching the objects? Is there a way to make a datamember of datacontract as reference to object in server?

Basically that is what you have got to do. You cannot directly transfer object references. A couple of things you could do- 1. Make object lookup dictionary based so that they are faster. 2. Pass the object id in the header of the request so that API is not cluttered with all of them taking object id. In your service contract you can first search the object with Id from header and then invoke method on that object. Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM