我有一个应用程序使用WebServices向客户端发送数据库记录(作为数组),但即使只发送1000条记录,它似乎很慢。c#WebService压缩
服务器在IIS 7上运行,客户端是WPF应用程序。基本上,我如何加快速度。我是否必须编写自定义压缩类或代码?在IIS服务器和/或客户端配置文件中只有一个设置是打开/关闭的?现在需要大约4-7秒才能返回这1000条记录。因此,当我们将可能返回10,000到40,000条记录的表绑定在一起时,我不希望用户在那里等待数据等待几分钟。
下面的代码的一个例子:
Foo.svc:
namespace Foo.Server
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
public sealed class FooService : IFoo
{
public SelectRecordsResponse SelectRecords(SelectRecordsRequest request)
{
//I tested to ensure that this isn't my bottleneck
FooBar[] records = ...; //Stores 1000 records
return new SelectRecordsResponse(records);
}
}
}
FooCommon.cs:
namespace Foo
{
[ServiceContract(Namespace = "http://www.company.com/Services/Foo", ConfigurationName = "IFoo")]
[ServiceKnownType(typeof(AbstractEntity))]
[XmlSerializerFormat(SupportFaults = true, Style = OperationFormatStyle.Document, Use = OperationFormatUse.Literal)]
public interface IFoo
{
[OperationContract(Action = "http://www.company.com/Services/Foo/SelectRecords",
ReplyAction = "http://www.company.com/Services/Foo/SelectRecordsReply",
Name = "SelectRecords")]
[ServiceKnownType(typeof(FooBar))]
[return: MessageParameter(Name = "Response")]
SelectRecordsResponse SelectRecords([MessageParameter(Name = "Request")]SelectRecordsRequest request);
}
[MessageContract(WrapperName = "SelectRecordsRequest", WrapperNamespace = "http://www.company.com/Services/Foo/", IsWrapped = true)]
public sealed class SelectRecordsRequest
{
public SelectRecordsRequest()
{
}
}
[MessageContract(WrapperName = "SelectRecordsResponse", WrapperNamespace = "http://www.company.com/Services/Foo/", IsWrapped = true)]
public sealed class SelectRecordsResponse
{
public SelectRecordsResponse()
{
Init();
}
public SelectRecordsResponse(FooBar[] records = null)
{
Init(records);
}
private void Init(FooBar[] records = null)
{
Records = records ?? new FooBar[0];
}
[MessageBodyMember(Namespace = "http://www.company.com/Services/Foo/", Order = 0, Name = "Records")]
[XmlArray(ElementName = "SelectRecordsArray", Form = XmlSchemaForm.Qualified)]
[XmlArrayItem(typeof(FooBar), ElementName = "SelectRecordsFooBar", Form = XmlSchemaForm.Qualified, IsNullable = true)]
private FooBar[] Records { get; set; }
}
}
FooClient.cs:
namespace Foo.Client
{
public interface IFooChannel : IFoo, IClientChannel
{
}
public sealed class FooClient : ClientBase<IFoo>, IFoo
{
public FooClient(String endpointConfigurationName) :
base(endpointConfigurationName)
{
}
public FooBar[] SelectRecords()
{
SelectRecordsRequest request = new SelectRecordsRequest();
SelectRecordsResponse response = ((IFoo)(Client)).SelectRecords(request);
return response.Records;
}
SelectRecordsResponse IFoo.SelectRecords(SelectRecordsRequest request)
{
return Channel.SelectRecords(request);
}
}
}
如果查询向客户端返回40000条记录,则查询很可能是错误的。在将结果返回给客户端之前,可能应该对结果进行汇总或过滤。 – 2010-11-03 15:15:32
你应该实现“分页”。你永远无法*一举返回40,000条记录。 – 2010-11-03 15:41:32
我确实正在过滤和分页,但有一些客户希望每个记录一次在数据网格中可见。无论哪种方式,100个记录或40,000我仍然需要实施某种压缩。 – 2010-11-03 15:50:19