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?