압축 된 (GZIP) JSON POST 요청을 수락하기 위해 WCF 클라우드 서비스 (Azure)를 사용하고 있습니다.WCF - 'System.IO.Compression.GZipStream'을 (를) 직렬화 할 수 없습니다.
내 클래스
[DataContract]
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class Omni : IOmnivore
{
public async Task<System.Net.HttpStatusCode> GetOmnisJson(GZipStream inputJsonStream)
{
JsonSerializer ser = new JsonSerializer();
using (var decompressor = new GZipStream(inputJsonStream, CompressionMode.Decompress))
using (var sr = new StreamReader(decompressor))
using (var jsonTextReader = new JsonTextReader(sr))
{
JObject jsonObj = (JObject)ser.Deserialize(jsonTextReader);
// extract necessary info
string dataType = (string)jsonObj["data_type"];
string dataTypeEvent = (string)jsonObj["event"];
내 인터페이스
[ServiceContract]
public interface IOmnivore
{
[OperationContract]
[WebInvoke(UriTemplate = "/PostOmnis",
Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
Task<System.Net.HttpStatusCode> GetOmnisJson(GZipStream json);
내 Web.config의 (HTTP 압축 부분)이 정말 웹에서 필요한 확실하지
.config. 이는 WCF가 <httpCompression><scheme dll>
부분에서, 푸른에 DLL 부분에 대해 확실하지 호스팅입니다 .. :
<system.webServer>
<httpCompression>
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
(JSON은 gzip으로 압축되는 입력부터) GZipStream
유형의 인수를 갖는 런타임 오류를 제공합니다 :
'System.IO.Compression.GZipStream' cannot be serialized. Consider marking it with the DataContractAttribute attribute.
내 수업은 이미 [DataContract]
으로 표시되어 있지만 다른 결과는 없습니다.
아이디어가 있으십니까?
GZip을 직접 할 필요가 없습니다. IIS가 자동으로 수행합니다. web.config에서 Dynamic Content Compression을 활성화하기 만하면됩니다. – Dai
어떻게 이런 짓을했는지 보여주기 위해 내 질문이 업데이트되었습니다. 여전히 충돌합니다. – Polis