Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - How to initialize object in WCF services

 
 
Old 04-22-2007   #1 (permalink)
Elvin


 
 

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 SpecsSystem Spec
Old 04-23-2007   #2 (permalink)
Arkady Frenkel


 
 

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 SpecsSystem Spec
Old 04-23-2007   #3 (permalink)
Elvin


 
 

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 SpecsSystem Spec
Old 04-23-2007   #4 (permalink)
Arkady Frenkel


 
 

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 SpecsSystem Spec
Old 04-23-2007   #5 (permalink)
Elvin


 
 

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 SpecsSystem Spec
Old 04-23-2007   #6 (permalink)
Arkady Frenkel


 
 

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 SpecsSystem Spec
Old 04-24-2007   #7 (permalink)
Elvin


 
 

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 SpecsSystem Spec
 

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46