2012-03-23 24 views
0

私はこれをしばらくの間行っており、これについての2番目の意見に本当に感謝しています。なぜ私が400 Bad Requestを得ているのか分からないようです。アップロードしようとしたときにWCFが400 Bad Requestを返す

WCFのWebコンフィグ

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="FileTransferServicesBinding" 
     transferMode="Streamed" messageEncoding="Mtom" 
     sendTimeout="01:05:00" receiveTimeout="00:10:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
maxNameTableCharCount="2147483647" /> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<behaviors> 
    <endpointBehaviors> 
    <behavior name="FileTransferServiceBehavior"> 

    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior name="FileTransferServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<services> 
    <service name="PP.Live.WCFService.MobileClient"> 
    <endpoint name="MobileClientEndpoint" binding="basicHttpBinding" bindingConfiguration="FileTransferServicesBinding" contract="PP.Live.WCFService.LiveService"/> 
    </service> 
</services> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

し、サービス契約:

[ServiceContract] 
public interface LiveService 
{ 
    [OperationContract] 
    [WebInvoke(Method = "POST")] 
    UploadMedia UploadFile(System.IO.Stream fileData); 


} 

[DataContract] 
public class UploadMedia 
{ 
    [DataMember] 
    public UploadStatus Status { get; set; } 

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

public enum UploadStatus 
{ 
    Success, 
    Error 
} 

そして、SVCは:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class MobileClient : LiveService 
{ 

    public UploadMedia UploadFile(System.IO.Stream fileData) 
    { 
     Trace.WriteLine("Uploading File"); 
     UploadMedia uploadMedia = new UploadMedia(); 
     try 
     { 
      //byte[] imageBytes = StreamHelper.ReadToEnd(fileData); 
      var memoryStream = new MemoryStream(); 
      fileData.CopyTo(memoryStream); 
      byte[] imageBytes = memoryStream.ToArray(); 

      memoryStream.Close(); 
      memoryStream.Dispose(); 

      string token = StoreFile(imageBytes); 

      fileData.Close(); 
      fileData.Dispose(); 

      if (!string.IsNullOrWhiteSpace(token)) 
      { 
       uploadMedia.Message = token; 
       uploadMedia.Status = UploadStatus.Success; 
      } 
      else 
      { 
       uploadMedia.Message = "No Token"; 
       uploadMedia.Status = UploadStatus.Error; 
      } 
     } 
     catch (Exception ex) 
     { 
      uploadMedia.Message = ex.Message + ex.StackTrace; 
      uploadMedia.Status = UploadStatus.Error; 

     } 

     return uploadMedia; 
    } 

は、この上で探してどうもありがとうございます私のために。

+0

正しい 'web.config'を投稿してください。あなたが投稿したものは不完全です。たとえば、開いている 'system.serviceModel'タグがありますが、閉じていません。 –

+0

クライアントの.configファイルはどのように見えますか? – Tung

答えて

1

basicHTTPBindingでメッセージのサイズを変更します。ファイルサイズがWCFで処理できるサイズを超えている可能性があります。

は、リンク以下を参照してください -

http://forums.asp.net/t/1299246.aspx/1

0

あなたは400 BadRequestを得ている理由を確認するためにあなたのサービスにTracingを有効にしてください。あなたがあなたの設定のようにあなたがbasicHttpBinding

を使用しているwebHttpBindingとして結合持つ必要がRESTfulな方法であなたのサービスにアクセスするために

はまた、あなたが識別するために、あなたのサービスのためのKnowType属性を使用していることを確認してくださいデシリアライズのためのUploadMediaとUploadStatusオブジェクト

関連する問題