![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | How to initialize object in WCF services Hi, below is my sample WCF service coding [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, ConcurrencyMode=ConcurrencyMode.Single)] public class GSMService:IGSMServer private static GSMObject gsm; public GSMService() { gsm=new GSMObject(); gsm.SMSReceoved+=new GSMObject.GSMSMSEventHandler(gsm_SMSReceived); .......... } } i has host the service in window form. The GSM object only be initial when the client make a first call. Is that possible when the host start i can initial the gsm object then waiting the client to connect to receive the incoming sms event? Thanks! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How to initialize object in WCF services R U sure. You constructor called when your call ServiceHost() in your app , and that have to be before first client's call Arkady "Elvin" <Elvin@discussions.microsoft.com> wrote in message news:3324C5D5-B5FA-4C8B-AA01-DCD7898FFA5D@microsoft.com... > Hi, below is my sample WCF service coding > > [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, > ConcurrencyMode=ConcurrencyMode.Single)] > public class GSMService:IGSMServer > > private static GSMObject gsm; > > public GSMService() > { > gsm=new GSMObject(); > gsm.SMSReceoved+=new GSMObject.GSMSMSEventHandler(gsm_SMSReceived); > .......... > } > } > > i has host the service in window form. The GSM object only be initial > when > the client make a first call. Is that possible when the host start i can > initial the gsm object then waiting the client to connect to receive the > incoming sms event? > > Thanks! |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to initialize object in WCF services yes, because the service need to turn on the GSM device to retrieve the sms message to do something even no client is call or attend. Once have client make a call the subscribe the operation contract then service will publish the info to the client. The other reason, is the service also need to do other job when it receive incoming sms, so the service cant depend on the client to wake up! i have think the alternative solution is make a client call from the host for the first time, but i dont think is a better design. hopefully you can give me some advice. Thanks! "Arkady Frenkel" wrote: > R U sure. You constructor called when your call ServiceHost() in your app , > and that have to be before first client's call > Arkady > > "Elvin" <Elvin@discussions.microsoft.com> wrote in message > news:3324C5D5-B5FA-4C8B-AA01-DCD7898FFA5D@microsoft.com... > > Hi, below is my sample WCF service coding > > > > [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, > > ConcurrencyMode=ConcurrencyMode.Single)] > > public class GSMService:IGSMServer > > > > private static GSMObject gsm; > > > > public GSMService() > > { > > gsm=new GSMObject(); > > gsm.SMSReceoved+=new GSMObject.GSMSMSEventHandler(gsm_SMSReceived); > > .......... > > } > > } > > > > i has host the service in window form. The GSM object only be initial > > when > > the client make a first call. Is that possible when the host start i can > > initial the gsm object then waiting the client to connect to receive the > > incoming sms event? > > > > Thanks! > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How to initialize object in WCF services What I meant when wrote : "R U sure ?" ( sorry forgot to put question mark ) , that GSMObject instantiated when GSMService() constructor called and that happen , not when client call the service method , but when you call ServiceHost() on the service, which have to be done before client first call, otherwise client just receive exception Arkady "Elvin" <Elvin@discussions.microsoft.com> wrote in message news:F1CA8FB6-3EB1-4E7E-AF3C-255E6092B8A8@microsoft.com... > yes, because the service need to turn on the GSM device to retrieve the > sms > message to do something even no client is call or attend. Once have client > make a call the subscribe the operation contract then service will publish > the info to the client. > The other reason, is the service also need to do other job when it receive > incoming sms, so the service cant depend on the client to wake up! > i have think the alternative solution is make a client call from the host > for the first time, but i dont think is a better design. > > hopefully you can give me some advice. Thanks! > > "Arkady Frenkel" wrote: > >> R U sure. You constructor called when your call ServiceHost() in your >> app , >> and that have to be before first client's call >> Arkady >> >> "Elvin" <Elvin@discussions.microsoft.com> wrote in message >> news:3324C5D5-B5FA-4C8B-AA01-DCD7898FFA5D@microsoft.com... >> > Hi, below is my sample WCF service coding >> > >> > [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, >> > ConcurrencyMode=ConcurrencyMode.Single)] >> > public class GSMService:IGSMServer >> > >> > private static GSMObject gsm; >> > >> > public GSMService() >> > { >> > gsm=new GSMObject(); >> > gsm.SMSReceoved+=new >> > GSMObject.GSMSMSEventHandler(gsm_SMSReceived); >> > .......... >> > } >> > } >> > >> > i has host the service in window form. The GSM object only be initial >> > when >> > the client make a first call. Is that possible when the host start i >> > can >> > initial the gsm object then waiting the client to connect to receive >> > the >> > incoming sms event? >> > >> > Thanks! >> >> >> |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How to initialize object in WCF services Hi Arkady, thanks for the info, appreciate you can show me some sample code for this? i try debug the the application but the new ServiceHost(typeof(GSMService)) does not trigger constructor GSMService(). Thanks! "Arkady Frenkel" wrote: > What I meant when wrote : "R U sure ?" ( sorry forgot to put question mark ) > , that GSMObject instantiated when GSMService() constructor called and that > happen , not when client call the service method , but when you call > ServiceHost() on the service, which have to be done before client first > call, otherwise client just receive exception > Arkady > > "Elvin" <Elvin@discussions.microsoft.com> wrote in message > news:F1CA8FB6-3EB1-4E7E-AF3C-255E6092B8A8@microsoft.com... > > yes, because the service need to turn on the GSM device to retrieve the > > sms > > message to do something even no client is call or attend. Once have client > > make a call the subscribe the operation contract then service will publish > > the info to the client. > > The other reason, is the service also need to do other job when it receive > > incoming sms, so the service cant depend on the client to wake up! > > i have think the alternative solution is make a client call from the host > > for the first time, but i dont think is a better design. > > > > hopefully you can give me some advice. Thanks! > > > > "Arkady Frenkel" wrote: > > > >> R U sure. You constructor called when your call ServiceHost() in your > >> app , > >> and that have to be before first client's call > >> Arkady > >> > >> "Elvin" <Elvin@discussions.microsoft.com> wrote in message > >> news:3324C5D5-B5FA-4C8B-AA01-DCD7898FFA5D@microsoft.com... > >> > Hi, below is my sample WCF service coding > >> > > >> > [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, > >> > ConcurrencyMode=ConcurrencyMode.Single)] > >> > public class GSMService:IGSMServer > >> > > >> > private static GSMObject gsm; > >> > > >> > public GSMService() > >> > { > >> > gsm=new GSMObject(); > >> > gsm.SMSReceoved+=new > >> > GSMObject.GSMSMSEventHandler(gsm_SMSReceived); > >> > .......... > >> > } > >> > } > >> > > >> > i has host the service in window form. The GSM object only be initial > >> > when > >> > the client make a first call. Is that possible when the host start i > >> > can > >> > initial the gsm object then waiting the client to connect to receive > >> > the > >> > incoming sms event? > >> > > >> > Thanks! > >> > >> > >> > > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: How to initialize object in WCF services Oops, I was wrong. You can create such with calling some static method. Add such to the class and call it after new ServiceHost() Arkady "Elvin" <Elvin@discussions.microsoft.com> wrote in message news:19BC0F29-EB9F-4318-B753-5F6D3EE42ED0@microsoft.com... > Hi Arkady, > > thanks for the info, appreciate you can show me some sample code for this? > i try debug the the application but the new > ServiceHost(typeof(GSMService)) > does not trigger constructor GSMService(). > > Thanks! > > > "Arkady Frenkel" wrote: > >> What I meant when wrote : "R U sure ?" ( sorry forgot to put question >> mark ) >> , that GSMObject instantiated when GSMService() constructor called and >> that >> happen , not when client call the service method , but when you call >> ServiceHost() on the service, which have to be done before client first >> call, otherwise client just receive exception >> Arkady >> >> "Elvin" <Elvin@discussions.microsoft.com> wrote in message >> news:F1CA8FB6-3EB1-4E7E-AF3C-255E6092B8A8@microsoft.com... >> > yes, because the service need to turn on the GSM device to retrieve the >> > sms >> > message to do something even no client is call or attend. Once have >> > client >> > make a call the subscribe the operation contract then service will >> > publish >> > the info to the client. >> > The other reason, is the service also need to do other job when it >> > receive >> > incoming sms, so the service cant depend on the client to wake up! >> > i have think the alternative solution is make a client call from the >> > host >> > for the first time, but i dont think is a better design. >> > >> > hopefully you can give me some advice. Thanks! >> > >> > "Arkady Frenkel" wrote: >> > >> >> R U sure. You constructor called when your call ServiceHost() in your >> >> app , >> >> and that have to be before first client's call >> >> Arkady >> >> >> >> "Elvin" <Elvin@discussions.microsoft.com> wrote in message >> >> news:3324C5D5-B5FA-4C8B-AA01-DCD7898FFA5D@microsoft.com... >> >> > Hi, below is my sample WCF service coding >> >> > >> >> > [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, >> >> > ConcurrencyMode=ConcurrencyMode.Single)] >> >> > public class GSMService:IGSMServer >> >> > >> >> > private static GSMObject gsm; >> >> > >> >> > public GSMService() >> >> > { >> >> > gsm=new GSMObject(); >> >> > gsm.SMSReceoved+=new >> >> > GSMObject.GSMSMSEventHandler(gsm_SMSReceived); >> >> > .......... >> >> > } >> >> > } >> >> > >> >> > i has host the service in window form. The GSM object only be >> >> > initial >> >> > when >> >> > the client make a first call. Is that possible when the host start >> >> > i >> >> > can >> >> > initial the gsm object then waiting the client to connect to receive >> >> > the >> >> > incoming sms event? >> >> > >> >> > Thanks! >> >> >> >> >> >> >> >> >> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: How to initialize object in WCF services Hi, you are right, change to static method will able to control from the host application, but all the related sub method also need to change to static as well. The alternative to initial the constructor when the host is start is change to InstanceContextMode.Single. Thanks! "Arkady Frenkel" wrote: > Oops, I was wrong. You can create such with calling some static method. Add > such to the class and call it after new ServiceHost() > Arkady > > > "Elvin" <Elvin@discussions.microsoft.com> wrote in message > news:19BC0F29-EB9F-4318-B753-5F6D3EE42ED0@microsoft.com... > > Hi Arkady, > > > > thanks for the info, appreciate you can show me some sample code for this? > > i try debug the the application but the new > > ServiceHost(typeof(GSMService)) > > does not trigger constructor GSMService(). > > > > Thanks! > > > > > > "Arkady Frenkel" wrote: > > > >> What I meant when wrote : "R U sure ?" ( sorry forgot to put question > >> mark ) > >> , that GSMObject instantiated when GSMService() constructor called and > >> that > >> happen , not when client call the service method , but when you call > >> ServiceHost() on the service, which have to be done before client first > >> call, otherwise client just receive exception > >> Arkady > >> > >> "Elvin" <Elvin@discussions.microsoft.com> wrote in message > >> news:F1CA8FB6-3EB1-4E7E-AF3C-255E6092B8A8@microsoft.com... > >> > yes, because the service need to turn on the GSM device to retrieve the > >> > sms > >> > message to do something even no client is call or attend. Once have > >> > client > >> > make a call the subscribe the operation contract then service will > >> > publish > >> > the info to the client. > >> > The other reason, is the service also need to do other job when it > >> > receive > >> > incoming sms, so the service cant depend on the client to wake up! > >> > i have think the alternative solution is make a client call from the > >> > host > >> > for the first time, but i dont think is a better design. > >> > > >> > hopefully you can give me some advice. Thanks! > >> > > >> > "Arkady Frenkel" wrote: > >> > > >> >> R U sure. You constructor called when your call ServiceHost() in your > >> >> app , > >> >> and that have to be before first client's call > >> >> Arkady > >> >> > >> >> "Elvin" <Elvin@discussions.microsoft.com> wrote in message > >> >> news:3324C5D5-B5FA-4C8B-AA01-DCD7898FFA5D@microsoft.com... > >> >> > Hi, below is my sample WCF service coding > >> >> > > >> >> > [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall, > >> >> > ConcurrencyMode=ConcurrencyMode.Single)] > >> >> > public class GSMService:IGSMServer > >> >> > > >> >> > private static GSMObject gsm; > >> >> > > >> >> > public GSMService() > >> >> > { > >> >> > gsm=new GSMObject(); > >> >> > gsm.SMSReceoved+=new > >> >> > GSMObject.GSMSMSEventHandler(gsm_SMSReceived); > >> >> > .......... > >> >> > } > >> >> > } > >> >> > > >> >> > i has host the service in window form. The GSM object only be > >> >> > initial > >> >> > when > >> >> > the client make a first call. Is that possible when the host start > >> >> > i > >> >> > can > >> >> > initial the gsm object then waiting the client to connect to receive > >> >> > the > >> >> > incoming sms event? > >> >> > > >> >> > Thanks! > >> >> > >> >> > >> >> > >> > >> > >> > > > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Inherit from usercontrol - Object not set to instance of an object | .NET General | |||
| datalist -- Object reference not set to an instance of an object. | .NET General | |||
| Initialize Junk Mail Filtering and MSOE.DLL could not initialize | Vista mail | |||
| Cryptographic Services service failed to initialize... | Vista performance & maintenance | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||