0

C# で構築している WCF RESTful (つまり、JSON) サービスがあります。DataContract メソッドの 1 つが非常に大きな応答を返す場合があり、最小で 10 MB、最大で 30 MB を超えることがあります。すべてテキストであり、JSON データとしてクライアントに返します。このメソッドをブラウザでテストすると、タイムアウトが発生します。WCF RESTful サービスの応答データを圧縮する方法があることを理解しています。相互運用性は私の目的にとって絶対に重要なので、WCF RESTful サービス応答データを圧縮することは可能ですか? 現在、私はまだローカル マシンでプロジェクトをテストしています。ただし、IIS に展開します。

相互運用性を持って圧縮する方法がある場合、これはどのように行うことができますか?

ありがとうございました。

これは実際に私が使用しているファイルのセットではありませんが、サービスの構築方法を示すサンプルにすぎません。このサンプルは圧縮をまったく必要としないことに気づきました。

IService1.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService4
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebInvoke(
            Method = "GET", 
            UriTemplate = "employees",
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare)]
        List<Employee> GetEmployees();
    }

    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class Employee
    {
        [DataMember]
        public string FirstName { get; set; }

        [DataMember]
        public string LastName { get; set; }

        [DataMember]
        public int Age { get; set; }

        public Employee(string firstName, string lastName, int age)
        {
            this.FirstName = firstName;
            this.LastName = lastName;
            this.Age = age;
        }
    }
}

Service1.svc.cs:

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.Net;

namespace WcfService4
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1
    {
        public List<Employee> GetEmployees()
        {
            // In reality, I'm calling the data from an external datasource, returning data to the client that exceeds 10 MB and can reach an upper limit of at least 30 MB.               

            List<Employee> employee = new List<Employee>();
            employee.Add(new Employee("John", "Smith", 28));
            employee.Add(new Employee("Jane", "Fonda", 42));
            employee.Add(new Employee("Brett", "Hume", 56));

            return employee;
        }
    }
}
4

1 に答える 1