.NET Framework Developer Center > .NET Development Forums > Windows Communication Foundation > Properties of a proxy to a service instead of method parameters?
Ask a questionAsk a question
 

AnswerProperties of a proxy to a service instead of method parameters?

  • Wednesday, November 04, 2009 10:19 AMtomer70 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Hi,

     

    My service exposes the following methods

     

    ConnectionInfo         Connect(ServerId,StoreId)

    Recipient[]                GetRecipients(ServerId,StoreId,MessageId)

    bool                          SendMessage(ServerId,StoreId,From,To,Body)

     

    Combining the ServerId and StoreId result in a key to a cache holding ‘MailServer’ com components,

    All methods accepts ServerId and StoreId 

    I want to let the client to use different proxy instances to the same mail server

    I was wondering if it is a good idea to make ServerId and StoreId, properties of a proxy?

    I understand that a custom OperationContext Is the way to do it?

    Assuming it is a good idea  my API will look like the following

     

       ConnectionInfo Connect(ServerID,StoreID)

       Recipient[]        GetRecipients(MessageId)

       Bool                SendMessage(From,To,Body)

     

     

     

    Proxy proxy =  new Proxy()

    ConnectionInfo info =proxy.Connect('ServerID','StoreID')
    proxy.StoreID = info.StoreID

    Proxy.ServerID=info.ServerID

     

    Thanks

      

Answers

  • Monday, November 09, 2009 9:36 AMtomer70 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    No,i want to create a VIEWSTATE like for WCF service.instead of caching or passing parametrs to a method,pass them as part of the message
    and extract them out of the operationcontext

    I think i understand now how  to do it.

    Thanks.

All Replies

  • Wednesday, November 04, 2009 12:28 PMMahesh Sabnis Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

      If you have StoreId and ServerId as separate variables in wcf service side ,Then this  required parameters you can put into a class as like below:

    [DataContract]
    public class MyParamaters
    {
      [DataMember]
      StoreID
      [DataMember]
      ServerID
    ...
    }

    once you create a proxy, this class will also be available to the client application and now client will pass instance on the class as input parameter to these methods as below:

    Myref is wcf service reference name.

    MyRef.Proxy proxy =  new MyRef.Proxy();
    MyRef.MyParameters obj = new MyRef.MyParameters();

    obj.ServerID = <value form client App>;
    obj.StoreId = <value form client App>;

    ConnectionInfo info =proxy.Connect(obj)


    Hope this will give you guideline...

    Regards

    Mahesh Sabnis

     

  • Wednesday, November 04, 2009 3:22 PMtomer70 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thanks

    But I want to avoid it; I want a ‘statefull’ proxy to a stateless service

     

    Tomer

  • Monday, November 09, 2009 9:32 AMBin-ze ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    If I understand you correctly, you can use a singleton patten to maintain the state between your client and service.
    If you set [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] on your service implementation (the singleton class), you can do this:

     MySingleton singleton = new MySingleton();
     ServiceHost host = new ServiceHost(singleton);
     host.Open();

    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Monday, November 09, 2009 9:36 AMtomer70 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    No,i want to create a VIEWSTATE like for WCF service.instead of caching or passing parametrs to a method,pass them as part of the message
    and extract them out of the operationcontext

    I think i understand now how  to do it.

    Thanks.