Is the thread-related Mono of the WCF Service hosting consistent with that of. Net?

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.