Properties of a proxy to a service instead of method parameters?
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.StoreIDProxy.ServerID=info.ServerID
Thanks
Answers
- 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.- Marked As Answer byBin-ze ZhaoMSFT, ModeratorTuesday, November 10, 2009 5:27 AM
All Replies
- 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 Thanks
But I want to avoid it; I want a ‘statefull’ proxy to a stateless serviceTomer
- 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. - 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.- Marked As Answer byBin-ze ZhaoMSFT, ModeratorTuesday, November 10, 2009 5:27 AM


