In the discussion of the mono 3.0.2 WCF application demo Based on duplex communication, Dr. Deep Blue raised the following question:
After several days, I finally understood myProgramWhere is the error? Add the following interface method to the service contract:
[Operationcontract]
Double sub (Double X, Double Y );
In this way, when the client calls the sub method, the returned value of the sub method can be directly obtained. However, when a service with the same function runs on Mono, the following error occurs:
Unhandled exception:
System. nullreferenceexception: object reference not set to an instance of an object
At system. servicemodel. description. callbackdebugbehavior. system. servicemodel. description. iendpointbehavior. applyclientbehavior (system. servicemodel. description. serviceendpoint endpoint, system. servicemodel. dispatcher. clientruntime behavior) [0x00000] in <FILENAME unknown>: 0
At system. servicemodel. description. serviceendpoint. createclientruntime (system. Object callbackdispatchruntime) [0x00000] in <FILENAME unknown>: 0
---------------
Therefore, the problem is that mono's WCF duplex service does not support methods.
Isoneway = false, that is, two-way service call.
================
Thank you very much for solving this problem!
This method runs well in windows and is not normal in Mono environment. Sometimes the "synchronous" Callback is required, which is also a reasonable requirement. I will test this method:
Add the usesynchronizationcontext of servicebehavir to the service implementation to set it. The default value of usesynchronizationcontext is true.
By default, the service operations of WCF implement Association for the synchonizationcontext of the current thread of the host service. The thread correlation with the callback operation is controlled through the usesynchronizationcontext of callbackbehavior. We set the usesynchronizationcontext of calculateservice to false.
Client callCode:
Then run it on mono.
When using the UI thread in Windows from, you must specify usesynchronizationcontext as false, which is not required in the console. In the running environment of Mono, you must specify usesynchronizationcontext to false. Does this show that Mono is more unified?
Code download
RelatedArticle:
Synchronization environment in WCF
Subsequent WCF journey (11): thread affinity)