圧縮(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部分についてはよく分から、Azureの上にないホストされている..:(入力JSONはgzip圧縮されているので)
<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" />
がGZipStream
型の引数を持つランタイムエラーを与えます:
'System.IO.Compression.GZipStream' cannot be serialized. Consider marking it with the DataContractAttribute attribute.
私のクラスは既に[DataContract]
とマークされていますが、私は別の結果を見ません。
アイデア?
GZipを自分で行う必要はありません。 IISはあなたのためにそれを行います - あなたはweb.configで動的コンテンツ圧縮を有効にするだけです。 – Dai
私はこれをどうやって行ったかを示すために質問を更新しました..まだクラッシュします。 – Polis