12,166
社区成员




using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService”。
[ServiceContract]
public interface IService
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: 在此添加您的服务操作
}
// 使用下面示例中说明的数据约定将复合类型添加到服务操作。
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、服务和配置文件中的类名“Service”。
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession,ConcurrencyMode=ConcurrencyMode.Multiple)]
public class Service : IService
{
public string GetData(int value)
{
DateTime startTime = DateTime.Now;
Int64 n = 30000000;
while (n > 0)
{
Math.Pow(33333333333333333.33333, 23333333);
n--;
}
DateTime endTime = DateTime.Now;
string msg = string.Format("服务端耗时:{2}ms,start:{0}_{1}", startTime.ToString("HH:mm:ss.ffffff"), endTime.ToString("HH:mm:ss.ffffff"),
(endTime - startTime).TotalMilliseconds);
Console.WriteLine(msg);
return string.Format("Server:{0},{1}", value,msg);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static Stopwatch sw = new Stopwatch();
static GTService.Service client = new GTService.Service();
class AAA
{
public int Value = -1;
public AAA(int value)
{
Value = value;
}
}
static void Main(string[] args)
{
sw.Start();
ThreadPool.SetMinThreads(25, 25);
for (int i = 0; i < 20; i++)
{
AAA a = new AAA(i);
System.Threading.ThreadPool.QueueUserWorkItem(DoWork,a);
}
Console.ReadKey();
}
static void DoWork(Object valuei)
{
AAA a = valuei as AAA;
int value = a.Value;
DateTime startTime = DateTime.Now;
string serverMsg=client.GetData(value, true);
DateTime endTime = DateTime.Now;
string clientMsg = string.Format("客户端耗时:{2}ms,start:{0}_{1},",
startTime.ToString("HH:mm:ss.ffffff"), endTime.ToString("HH:mm:ss.ffffff"),
(endTime - startTime).TotalMilliseconds);
string msg = string.Format("累计时长:{3}ms,client:{0},{1}__{2}",
value, clientMsg, serverMsg,sw.ElapsedMilliseconds);
Console.WriteLine(msg);
Debug.WriteLine(msg);
}
}
}
<binding name="BasicHttpBindingCharge" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxBufferSize="65536000" maxReceivedMessageSize="65536000"
textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="false"
messageEncoding="Text">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<configuration>
<system.net>
<connectionManagement>
<add address = "*" maxconnection = "2" />
</connectionManagement>
</system.net>
</configuration>