1

私のサービス コントラクトでは、Streamをパラメーターとして受け取るメソッドを公開しています。

[OperationContract]
[WebInvoke(UriTemplate = "/Upload?fileName={fileName}", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Stream Upload(String fileName, Stream fileData);

これを行うと、カスタム WebServiceHost 実装 (カスタム WebServiceHostFactory 実装からインスタンス化されます) は、エンドポイント バインディングを WebHttpBinding ではなく CustomBinding として認識します。

public class myWebServiceHost : WebServiceHost {
  .
  .
  .
  protected override void OnOpening() {
    base.OnOpening();
    if (base.Description != null) {
      foreach (ServiceEndpoint endpoint in base.Description.Endpoints) {
        WebHttpBinding binding = endpoint.Binding as WebHttpBinding;
        if (binding != null) { //Will always be null given the operation contract above
          Int32 MB = 1048576 * Convert.ToInt32(ConfigurationManager.AppSettings["requestSizeMax"]);
          binding.MaxReceivedMessageSize = MB;
          binding.TransferMode = TransferMode.Streamed;
        }
      }
    }
  }
}

64KB を超えるファイルをアップロードする必要があるため、これは問題です... CustomBinding に MaxReceivedMessageSize を設定する方法、または Binding が WebHttpBinding に設定されるようにする方法についてのアイデア。

PSこれをプログラムで行う必要があるため、.config設定は役に立ちません。

4

1 に答える 1