Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

How to initialize object in WCF services

Update your Vista Drivers Update Your Drivers Now!!
 
 
Thread Tools Display Modes
Old 04-22-2007   #1 (permalink)
Elvin
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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
Guest


 

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-23-2007   #7 (permalink)
Elvin
Guest


 

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
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
datalist -- Object reference not set to an instance of an object. Deere .NET General 0 08-31-2008 09:09 AM
Initialize Junk Mail Filtering and MSOE.DLL could not initialize RainbowKid Vista mail 13 03-04-2008 11:36 PM
Cryptographic Services service failed to initialize... Ex_Brit Vista performance & maintenance 0 08-18-2007 01:54 PM
Testing object arrays using Compare-Object and -contains Alex K. Angelopoulos [MVP] PowerShell 2 08-31-2006 05:57 PM
Adding canonical aliases for Compare-Object, Measure-Object, New-Object Alex K. Angelopoulos [MVP] PowerShell 2 05-26-2006 07:58 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51