ProtocolException.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel
  5. {
  6. using System.Globalization;
  7. using System.Runtime.Serialization;
  8. using System.ServiceModel.Channels;
  9. [Serializable]
  10. public class ProtocolException : CommunicationException
  11. {
  12. public ProtocolException() { }
  13. public ProtocolException(string message) : base(message) { }
  14. public ProtocolException(string message, Exception innerException) : base(message, innerException) { }
  15. protected ProtocolException(SerializationInfo info, StreamingContext context) : base(info, context) { }
  16. internal static ProtocolException ReceiveShutdownReturnedNonNull(Message message)
  17. {
  18. if (message.IsFault)
  19. {
  20. try
  21. {
  22. MessageFault fault = MessageFault.CreateFault(message, 64 * 1024);
  23. FaultReasonText reason = fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture);
  24. string text = SR.GetString(SR.ReceiveShutdownReturnedFault, reason.Text);
  25. return new ProtocolException(text);
  26. }
  27. catch (QuotaExceededException)
  28. {
  29. string text = SR.GetString(SR.ReceiveShutdownReturnedLargeFault, message.Headers.Action);
  30. return new ProtocolException(text);
  31. }
  32. }
  33. else
  34. {
  35. string text = SR.GetString(SR.ReceiveShutdownReturnedMessage, message.Headers.Action);
  36. return new ProtocolException(text);
  37. }
  38. }
  39. internal static ProtocolException OneWayOperationReturnedNonNull(Message message)
  40. {
  41. if (message.IsFault)
  42. {
  43. try
  44. {
  45. MessageFault fault = MessageFault.CreateFault(message, 64 * 1024);
  46. FaultReasonText reason = fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture);
  47. string text = SR.GetString(SR.OneWayOperationReturnedFault, reason.Text);
  48. return new ProtocolException(text);
  49. }
  50. catch (QuotaExceededException)
  51. {
  52. string text = SR.GetString(SR.OneWayOperationReturnedLargeFault, message.Headers.Action);
  53. return new ProtocolException(text);
  54. }
  55. }
  56. else
  57. {
  58. string text = SR.GetString(SR.OneWayOperationReturnedMessage, message.Headers.Action);
  59. return new ProtocolException(text);
  60. }
  61. }
  62. }
  63. }