How can a client call the wcf Service to improve call performance and call

Source: Internet
Author: User

How can a client call the wcf Service to improve call performance and call

IO call service

1. Use using (automatically released each time)

For (var I = 0; I <10; I ++) {var watch = new Stopwatch (); watch. start (); using (var client = new StreamServiceClient () {var result = client. upload (new StreamRequest {Bytes = data, FileExt = ext, Passport = ""}); if (! String. isNullOrEmpty (result. msg) MessageBox. show (result. msg);} watch. stop (); this. richTextBox1.AppendText (string. format ("Times {0}: Time consumed: {1} \ r \ n", I, watch. elapsedMilliseconds ));}View Code

Time consumed:

2. Reuse the wcf communication channel

For (var I = 0; I <10; I ++) {var watch = new Stopwatch (); watch. start (); var client = new StreamServiceClient (); {var result = client. upload (new StreamRequest {Bytes = data, FileExt = ext, Passport = ""}); if (! String. isNullOrEmpty (result. msg) MessageBox. show (result. msg);} watch. stop (); this. richTextBox1.AppendText (string. format ("Times {0}: Time consumed: {1} \ r \ n", I, watch. elapsedMilliseconds ));}View Code

Time consumed:

3. Custom wcf Channel

Create a channel first, as shown below:

/// <Summary> // IO service channel // by: jgl // date: 15-10-10 // </summary> public sealed class EmpIOChannelFacotry {private static readonly object LockObject = new object (); private static StreamServiceClient client; public static StreamServiceClient Channel {get {lock (LockObject) {var locaClient = client; if (locaClient! = Null & locaClient. State! = CommunicationState. faulted) return locaClient; client = new StreamServiceClient (); return client ;}} set {lock (LockObject) {if (client = null) return; if (client. state! = CommunicationState. Opened) client. Abort (); client. Close (); client = value ;}}}}View Code

Time consumed:

 

This article is a personal record. I am a newbie of wcf. I hope you will give more criticism and advice.

Can you provide other methods for calling a wcf client?

 

Related Article

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.