[Mono-osx] Mono - WCF

Adam adam at irisdesign.co.nz
Tue Oct 16 18:34:28 UTC 2012


hi,

Your problem is, your WCF setup doesnt make sense for your purpose.
You are using:
InstanceContextMode=InstanceContextMode.PerCall

This means that a new instance of your service class is instantiated every
time a request comes in - so you will never be able to refer to an instance
of the service that started the thread (i.e., you will set ' needToExit =
true;' inside of a service that has just been created, and has no running
thread).

You need to change to another instance-context, such as Single, or
PerSession.

Adam

On Wed, Oct 17, 2012 at 12:31 AM, sheen <sheenchandy at verifaya.com> wrote:

> Hi,
>
> I have an issue in calling WCF Services.
> I will explain issue using below example
>
> WCF Interface :
>
> [ServiceContract]
> public interface IWcfServer
> {
>         [OperationContract]
>         void LongRunningFunction();
>         [OperationContract]
>         void StopLongRunningFunction();
> }
>
> WCF Service :
>
>
> [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall,ConcurrencyMode=ConcurrencyMode.Multiple)]
> public class WfcServer : IWcfServer
> {
>         public static bool needToExit = false;
>         public void LongRunningFunction()
>         {
>                 Thread t = new Thread(LongRunningProcess);
>                 t.Start();
>                 t.Join();
>         }
>         public void StopLongRunningFunction()
>         {
>                 needToExit = true;
>         }
>         private void LongRunningProcess ()
>         {
>                 while (true) {
>                         if(needToExit)
>                                   break;
>                         System.Threading.Thread.Sleep(1000);
>                 }
>         }
> }
>
> Config file
>
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
>   <system.serviceModel>
>     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
>     <behaviors>
>       <serviceBehaviors>
>         <behavior name="SampleWcf.WfcServerBehavior">
>           <serviceMetadata httpGetEnabled="true" />
>           <serviceDebug includeExceptionDetailInFaults="true" />
>         </behavior>
>       </serviceBehaviors>
>       <endpointBehaviors>
>         <behavior name="webHttpBehavior">
>           <webHttp />
>         </behavior>
>       </endpointBehaviors>
>     </behaviors>
>     <bindings>
>       <webHttpBinding>
>         <binding name="webHttpBind"/>
>       </webHttpBinding>
>     </bindings>
>     <services>
>       <service name="SampleWcf.WfcServer"
> behaviorConfiguration="SampleWcf.WfcServerBehavior">
>         <endpoint name="WfcServer" address="" binding="webHttpBinding"
>                   bindingConfiguration="webHttpBind"
> contract="WcfInterface.IWcfServer"
>                   behaviorConfiguration="webHttpBehavior"/>
>       </service>
>     </services>
>   </system.serviceModel>
> </configuration>
>
> WCF Client:
>
> From WCF Client first i will call LongRunningFunction() and then
> StopLongRunningFunction(). My issue is in calling StopLongRunningFuction().
> StopLongRunningFuction() get called after a long time (nearly 5 min).
> Please help me to resolve this issue.
>
>
> Thanks & Regards
> Sheen
>
>
>
>
> --
> View this message in context:
> http://mono.1490590.n4.nabble.com/Mono-WCF-tp4656979.html
> Sent from the Mono - OSX mailing list archive at Nabble.com.
> _______________________________________________
> Mono-osx mailing list
> Mono-osx at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-osx
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-osx/attachments/20121017/3313ab19/attachment.html>


More information about the Mono-osx mailing list