2012-08-23 2 views
0

100 개가 넘는 감사 항목을 보내려고하면 "원격 서버에서 예기치 않은 응답을 반환했습니다 : (400) Bad Request"가 나타납니다. 디버깅에 도움이되는 Fiddler를 사용 중이며 서버에 요청을 보았습니다. 클라이언트와 서버 모두 동일한 인터페이스를 사용합니다.WCF : 소량의 데이터를 보낼 때 잘못된 요청 받기 (400)

[ServiceContract] 
public interface ISyncDataContract 
{ 
    #region Audit Log 

    /// <summary> 
    /// Creates a collection of new audit entries items in the database. 
    /// </summary> 
    /// <param name="items">The audit entry items to be created.</param> 
    /// <returns><c>True</c> if created successfully; otherwise, <c>false</c>.</returns> 
    [OperationContract] 
    [WebInvoke(UriTemplate = "AuditEntries", Method = "PUT")] 
    bool CreateAuditEntryItems(AuditEntryItemCollection items); 

    /// <summary> 
    /// Gets all the audit entry items available. 
    /// </summary> 
    /// <returns>An <see cref="AuditEntryItemCollection"/> object containing all the 
    /// available audit entry items.</returns> 
    [OperationContract] 
    [WebGet(UriTemplate = "AuditEntries")] 
    Message GetAuditEntryItems(); 

    #endregion 
} 

AuditEntryItem.cs

[DataContract] 
public class AuditEntryItem 
{ 
    #region Constructor/Deconstructor 

    /// <summary> 
    /// Initializes a new instance of the <see cref="AuditEntryItem"/> class. 
    /// </summary> 
    public AuditEntryItem() 
    { 
    } 

    /// <summary> 
    /// Initializes a new instance of the <see cref="AuditEntryItem"/> class. 
    /// </summary> 
    /// <param name="auditEntry">The audit entry.</param> 
    public AuditEntryItem(AuditEntry auditEntry) 
    { 
     if (auditEntry == null) 
     { 
      throw new ArgumentNullException("auditEntry"); 
     } 

     this.Audit_Type = auditEntry.Audit_type; 
     this.ComputerName = Environment.MachineName; 
     this.Message = auditEntry.Message; 
     this.Sequence_Number = auditEntry.Sequence_number; 
     this.Session_ID = auditEntry.Session_ID; 
     this.SyncDate = DateTime.Now; 
     this.Time_Stamp = auditEntry.Time_stamp; 
     this.User_ID = auditEntry.User_ID; 
    } 

    #endregion Constructor/Deconstructor 

    #region Properties 

    /// <summary> 
    /// Gets or sets the session ID. 
    /// </summary> 
    /// <value> 
    /// The session ID. 
    /// </value> 
    [DataMember] 
    [XmlElement(ElementName = @"Session_ID")] 
    public string Session_ID { get; set; } 

    /// <summary> 
    /// Gets or sets the user ID. 
    /// </summary> 
    /// <value> 
    /// The user ID. 
    /// </value> 
    [DataMember] 
    [XmlElement(ElementName = @"User_ID")] 
    public string User_ID { get; set; } 

    /// <summary> 
    /// Gets or sets the time stamp. 
    /// </summary> 
    /// <value> 
    /// The time stamp. 
    /// </value> 
    [DataMember] 
    [XmlElement(ElementName = @"Time_Stamp")] 
    public string Time_Stamp { get; set; } 

    /// <summary> 
    /// Gets or sets the sequence number. 
    /// </summary> 
    /// <value> 
    /// The sequence number. 
    /// </value> 
    [DataMember] 
    [XmlElement(ElementName = @"Sequence_number")] 
    public int Sequence_Number { get; set; } 

    /// <summary> 
    /// Gets or sets the message. 
    /// </summary> 
    /// <value> 
    /// The message. 
    /// </value> 
    [DataMember] 
    [XmlElement(ElementName = @"Message")] 
    public string Message { get; set; } 

    /// <summary> 
    /// Gets or sets the type of the audit. 
    /// </summary> 
    /// <value> 
    /// The type of the audit. 
    /// </value> 
    [DataMember] 
    [XmlElement(ElementName = @"Audit_type")] 
    public string Audit_Type { get; set; } 

    /// <summary> 
    /// Gets or sets the name of the computer. 
    /// </summary> 
    /// <value> 
    /// The name of the computer. 
    /// </value> 
    [DataMember] 
    [XmlElement(ElementName = @"ComputerName")] 
    public string ComputerName { get; set; } 

    /// <summary> 
    /// Gets or sets the sync date. 
    /// </summary> 
    /// <value> 
    /// The sync date. 
    /// </value> 
    [DataMember] 
    [XmlElement(ElementName = @"SyncDate")] 
    public DateTime? SyncDate { get; set; } 

    /// <summary> 
    /// Gets the time stamp value in a date time format. 
    /// </summary> 
    [XmlIgnore] 
    public DateTime DisplayTimeStamp 
    { 
     get { return this.TimeStampDateTime(); } 
    } 

    #endregion Properties 

    #region Overrides 

    public override bool Equals(object obj) 
    { 
     return obj is AuditEntryItem ? this.Equals((AuditEntryItem)obj) : false; 
    } 

    public bool Equals(AuditEntryItem other) 
    { 
     if (ReferenceEquals(this, other)) 
     { 
      return true; 
     } 

     return string.Equals(this.Audit_Type, other.Audit_Type) && 
       string.Equals(this.ComputerName, other.ComputerName) && 
       string.Equals(this.Message, other.Message) && 
       this.Sequence_Number == other.Sequence_Number && 
       string.Equals(this.Session_ID, other.Session_ID) && 
       this.SyncDate == other.SyncDate && 
       string.Equals(this.Time_Stamp, other.Time_Stamp) && 
       string.Equals(this.User_ID, other.User_ID); 
    } 

    public override int GetHashCode() 
    { 
     unchecked 
     { 
      var result = (this.Audit_Type != null ? this.Audit_Type.GetHashCode() : 0); 
      result = (result * 397)^(this.ComputerName != null ? this.ComputerName.GetHashCode() : 0); 
      result = (result * 397)^(this.Message != null ? this.Message.GetHashCode() : 0); 
      result = (result * 397)^this.Sequence_Number.GetHashCode(); 

      result = (result * 397)^(this.Session_ID != null ? this.Session_ID.GetHashCode() : 0); 
      result = (result * 397)^(this.SyncDate != null ? this.SyncDate.GetHashCode() : 0); 
      result = (result * 397)^(this.Time_Stamp != null ? this.Time_Stamp.GetHashCode() : 0); 
      result = (result * 397)^(this.User_ID != null ? this.User_ID.GetHashCode() : 0); 
      return result; 
     } 
    } 

    #endregion Overrides 

    /// <summary> 
    /// Converts the Java time stamp value into a readable format. 
    /// </summary> 
    /// <returns>A readable date time format.</returns> 
    private DateTime TimeStampDateTime() 
    { 
     if (this.Time_Stamp.IsNullOrEmpty()) 
     { 
      return new DateTime(1970, 01, 01); 
     } 

     long value; 
     if (!long.TryParse(this.Time_Stamp, out value)) 
     { 
      return new DateTime(1970, 01, 01); 
     } 

     value = value/1000; 
     return new DateTime(1970, 01, 01).AddSeconds(value); 
    } 
} 

AuditEntryItemCollection.cs

[DataContract] 
[XmlRoot(ElementName = "AuditLog")] 
public class AuditEntryItemCollection 
{ 
    #region Declarations 

    #endregion Declarations 

    #region Constructor/Deconstructor 

    /// <summary> 
    /// Initializes a new instance of the <see cref="AuditEntryItemCollection"/> class. 
    /// </summary> 
    public AuditEntryItemCollection() 
    { 
     this.AuditEntryItems = new List<AuditEntryItem>(); 
    } 

    #endregion Constructor/Deconstructor 

    #region Properties 

    /// <summary> 
    /// Gets or sets the collection of <see cref="AuditEntryItem"/> 
    /// objects. 
    /// </summary> 
    /// <value> 
    /// The collection of <see cref="AuditEntryItem"/> objects. 
    /// </value> 
    [XmlElement(ElementName = @"AuditEntry")] 
    [DataMember] 
    public List<AuditEntryItem> AuditEntryItems { get; set; } 

    #endregion Properties 
} 

의 App.config

<?xml version="1.0" encoding="utf-8" ?> 

<behaviors> 
    <endpointBehaviors> 
    <behavior name="restXmlBehavior"> 
     <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Xml" /> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
    </behavior> 
    <behavior name="rssAtomBehavior"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 

    <serviceBehaviors> 
    <behavior name="metadataBehavior" > 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<bindings> 
    <webHttpBinding> 
    <binding name="StreamedHttp" 
      maxReceivedMessageSize="2147483647" 
      transferMode="Streamed" > 
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="6000000" /> 
    </binding> 
    </webHttpBinding> 
</bindings> 

UPDATE :

내가 지금 무엇입니까 오류가 수신 메시지 (65536)의 최대 메시지 크기 할당량이 초과되었습니다 "입니다. 할당량을 늘리려면 해당 바인딩 요소에 대해 MaxReceivedMessageSize 속성을 사용하십시오. "내가 알 수있는 한 이미이 작업을 수행했습니다. 설정해야 할 다른 설정이 있습니까?

+1

서버에 액세스 할 수 있습니까? Windows 이벤트 뷰어에서 오류를 확인하십시오. 서비스 추적 뷰어도 확인하십시오. http://msdn.microsoft.com/en-us/library/ms732023.aspx –

+0

잘못된 요청을받는 정확한 원인을 파악하려면 서비스 추적을 사용하십시오. 또한 Fiddler에서 원시 요청이 어떻게 보이는지 게시하십시오. – Rajesh

답변

2

httpRuntime이 대형 요청을 구성 :

가 (예 내가 파일 : 업로드하는 데 사용하는 서비스에서 잡고

<httpRuntime executionTimeout="3600" maxRequestLength="50000000" maxQueryStringLength="2097151" requestValidationMode="2.0" /> 

또한 아마도 다시 (바인딩의 버퍼 풀 크기를 보면,이 값은 단지 예 :

<binding name="WHB" maxReceivedMessageSize="50000000" maxBufferPoolSize="50000000" crossDomainScriptAccessEnabled="true"> 
      <readerQuotas maxArrayLength="50000000" maxStringContentLength="50000000" /> 
관련 문제