本文整理汇总了C#中System.ServiceModel.Channels.MessageVersion类的典型用法代码示例。如果您正苦于以下问题:C# MessageVersion类的具体用法?C# MessageVersion怎么用?C# MessageVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageVersion类属于System.ServiceModel.Channels命名空间,在下文中一共展示了MessageVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PromoteException
//Can only be called inside a service
public static void PromoteException(Exception error,MessageVersion version,ref Message fault)
{
StackFrame frame = new StackFrame(1);
Type serviceType = frame.GetMethod().ReflectedType;
PromoteException(serviceType,error,version,ref fault);
}
示例2: ProvideFault
//- @ProvideFault -//
public virtual void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
fault.Properties[HttpResponseMessageProperty.Name] = new HttpResponseMessageProperty
{
StatusCode = HttpStatusCode.OK
};
}
示例3: ErrorBehavior
internal ErrorBehavior(ChannelDispatcher channelDispatcher)
{
this.handlers = EmptyArray<IErrorHandler>.ToArray(channelDispatcher.ErrorHandlers);
this.debug = channelDispatcher.IncludeExceptionDetailInFaults;
this.isOnServer = channelDispatcher.IsOnServer;
this.messageVersion = channelDispatcher.MessageVersion;
}
示例4: ProvideFault
/// <summary>
/// Enables the creation of a custom System.ServiceModel.FaultException{TDetail}
/// that is returned from an exception in the course of a service method.
/// </summary>
/// <param name="error">The System.Exception object thrown in the course of the service operation.</param>
/// <param name="version">The SOAP version of the message.</param>
/// <param name="fault">
/// The System.ServiceModel.Channels.Message object that is returned to the client, or service in
/// duplex case
/// </param>
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
if (error is FaultException<ApplicationServiceError>)
{
var messageFault = ((FaultException<ApplicationServiceError>) error).CreateMessageFault();
//propagate FaultException
fault = Message.CreateMessage(
version,
messageFault,
((FaultException<ApplicationServiceError>) error).Action);
}
else
{
//create service error
var defaultError = new ApplicationServiceError()
{
ErrorMessage = Messages.message_DefaultErrorMessage
};
//Create fault exception and message fault
var defaultFaultException = new FaultException<ApplicationServiceError>(defaultError);
var defaultMessageFault = defaultFaultException.CreateMessageFault();
//propagate FaultException
fault = Message.CreateMessage(version, defaultMessageFault, defaultFaultException.Action);
}
}
示例5: ProvideFault
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
FaultException faultException;
var logger = LogManager.GetCurrentClassLogger();
if (error != null && error is ObjectValidationException)
{
faultException = new FaultException<ValidationFault>(new ValidationFault(((ObjectValidationException)error).ValidationErrors.Select(item =>
new ValidationError
{
ErrorMessage = item.ErrorMessage,
ObjectName = item.ObjectName,
PropertyName = item.PropertyName
})), new FaultReason("Validation error"));
logger.Error(error, "Validation error in GlobalError filter");
}
else
{
faultException = new FaultException<InternalServiceFault>(new InternalServiceFault(error,
string.Format("Exception caught at GlobalErrorHandler{0}Method: {1}{2}Message:{3}",
Environment.NewLine, error.TargetSite.Name, Environment.NewLine, error.Message)));
logger.Error(error, "Generic internal error in GlobalError filter");
}
// Shield the unknown exception
//FaultException faultException = new FaultException<SimpleErrorFault>(new SimpleErrorFault(), new FaultReason("Server error encountered. All details have been logged."));
//new FaultException("Server error encountered. All details have been logged.");
MessageFault messageFault = faultException.CreateMessageFault();
fault = Message.CreateMessage(version, messageFault, faultException.Action);
}
示例6: ProvideFault
internal Message ProvideFault(MessageVersion messageVersion)
{
WSAddressing10ProblemHeaderQNameFault fault = new WSAddressing10ProblemHeaderQNameFault(this);
Message message = Message.CreateMessage(messageVersion, fault, messageVersion.Addressing.FaultAction);
fault.AddHeaders(message.Headers);
return message;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:ActionMismatchAddressingException.cs
示例7: SerializeReply
public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
{
WebOperationContext currentContext = WebOperationContext.Current;
OutgoingWebResponseContext outgoingResponse = null;
if (currentContext != null)
{
outgoingResponse = currentContext.OutgoingResponse;
}
WebMessageFormat format = this.defaultFormat;
if (outgoingResponse != null)
{
WebMessageFormat? nullableFormat = outgoingResponse.Format;
if (nullableFormat.HasValue)
{
format = nullableFormat.Value;
}
}
if (!this.formatters.ContainsKey(format))
{
string operationName = "<null>";
if (OperationContext.Current != null)
{
MessageProperties messageProperties = OperationContext.Current.IncomingMessageProperties;
if (messageProperties.ContainsKey(WebHttpDispatchOperationSelector.HttpOperationNamePropertyName))
{
operationName = messageProperties[WebHttpDispatchOperationSelector.HttpOperationNamePropertyName] as string;
}
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR2.GetString(SR2.OperationDoesNotSupportFormat, operationName, format.ToString())));
}
if (outgoingResponse != null && string.IsNullOrEmpty(outgoingResponse.ContentType))
{
string automatedSelectionContentType = outgoingResponse.AutomatedFormatSelectionContentType;
if (!string.IsNullOrEmpty(automatedSelectionContentType))
{
// Don't set the content-type if it is default xml for backwards compatiabilty
if (!string.Equals(automatedSelectionContentType, defaultContentTypes[WebMessageFormat.Xml], StringComparison.OrdinalIgnoreCase))
{
outgoingResponse.ContentType = automatedSelectionContentType;
}
}
else
{
// Don't set the content-type if it is default xml for backwards compatiabilty
if (format != WebMessageFormat.Xml)
{
outgoingResponse.ContentType = defaultContentTypes[format];
}
}
}
Message message = this.formatters[format].SerializeReply(messageVersion, parameters, result);
return message;
}
示例8: OnImportPolicy
protected virtual void OnImportPolicy (XmlElement assertion,
MessageVersion messageVersion,
MetadataImporter exporter,
PolicyConversionContext context)
{
throw new NotImplementedException ();
}
示例9: CustomTextMessageEncoderFactory
internal CustomTextMessageEncoderFactory(string mediaType, string charSet, MessageVersion version)
{
_version = version;
_mediaType = mediaType;
_charSet = charSet;
_encoder = new CustomTextMessageEncoder(this);
}
示例10: SerializeReply
public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
{
JObject json = new JObject();
json[JsonRpcConstants.ErrorKey] = null;
json[JsonRpcConstants.ResultKey] = JToken.FromObject(result);
return JsonRpcHelpers.SerializeMessage(json, null);
}
示例11: ProvideFault
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
Contract.Requires<NullReferenceException>(error != null);
FaultCode code = FaultCode.CreateSenderFaultCode(error.GetType().Name, FaultNs);
fault = Message.CreateMessage(version, code, error.Message, null);
if (this.Context != null)
{
var se = error as ServiceException;
if (se != null)
{
Context.OutgoingResponse.StatusCode = ((ServiceException)error).StatusCode;
}
var sb = new StringBuilder();
for (int i = 0; i < error.Message.Length; i++)
{
var ch = (char)('\x00ff' & error.Message[i]);
if (((ch <= '\x001f') && (ch != '\t')) || (ch == '\x007f'))
{
// Specified value has invalid Control characters.
// See HttpListenerResponse.StatusDescription implementation.
}
else
{
sb.Append(ch);
}
}
Context.OutgoingResponse.StatusDescription = sb.ToString();
Context.OutgoingResponse.SuppressEntityBody = false;
}
}
示例12: ArgumentNullException
/// <summary>
/// Serializes a reply message from a specified message version, array of parameters, and a return value.
/// </summary>
/// <param name="messageVersion">The SOAP message version.</param>
/// <param name="parameters">The out parameters.</param>
/// <param name="result">The return value.</param>
/// <returns>he serialized reply message.</returns>
Message IDispatchMessageFormatter.SerializeReply(
MessageVersion messageVersion,
object[] parameters,
object result)
{
if (parameters == null)
{
throw new ArgumentNullException("parameters");
}
if (messageVersion != MessageVersion.None)
{
throw new NotSupportedException(
string.Format(
CultureInfo.CurrentCulture,
SR.HttpMessageFormatterMessageVersion,
this.GetType()));
}
HttpResponseMessage response = this.GetDefaultResponse();
if (response == null)
{
throw new InvalidOperationException(
string.Format(
CultureInfo.CurrentCulture,
SR.HttpMessageFormatterNullResponse,
this.GetType()));
}
this.SerializeReply(parameters, result, response);
return response.ToMessage();
}
示例13: CreateMessage
public Message CreateMessage(MessageVersion messageVersion, ReliableMessagingVersion reliableMessagingVersion)
{
this.SetReliableMessagingVersion(reliableMessagingVersion);
string faultActionString = WsrmIndex.GetFaultActionString(messageVersion.Addressing, reliableMessagingVersion);
if (messageVersion.Envelope == EnvelopeVersion.Soap11)
{
this.code = this.Get11Code(this.code, this.subcode);
}
else
{
if (messageVersion.Envelope != EnvelopeVersion.Soap12)
{
throw Fx.AssertAndThrow("Unsupported MessageVersion.");
}
if (this.code.SubCode == null)
{
FaultCode subCode = new FaultCode(this.subcode, WsrmIndex.GetNamespaceString(reliableMessagingVersion));
this.code = new FaultCode(this.code.Name, this.code.Namespace, subCode);
}
this.hasDetail = this.Get12HasDetail();
}
Message message = Message.CreateMessage(messageVersion, this, faultActionString);
this.OnFaultMessageCreated(messageVersion, message);
return message;
}
示例14: BufferedHeader
public BufferedHeader(MessageVersion version, XmlBuffer buffer, XmlDictionaryReader reader, XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes)
{
this.streamed = true;
this.buffer = buffer;
this.version = version;
MessageHeader.GetHeaderAttributes(reader, version, out this.actor, out this.mustUnderstand, out this.relay, out this.isRefParam);
this.name = reader.LocalName;
this.ns = reader.NamespaceURI;
this.bufferIndex = buffer.SectionCount;
XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
writer.WriteStartElement("Envelope");
if (envelopeAttributes != null)
{
XmlAttributeHolder.WriteAttributes(envelopeAttributes, writer);
}
writer.WriteStartElement("Header");
if (headerAttributes != null)
{
XmlAttributeHolder.WriteAttributes(headerAttributes, writer);
}
writer.WriteNode(reader, false);
writer.WriteEndElement();
writer.WriteEndElement();
buffer.CloseSection();
}
示例15: ProvideFault
public void ProvideFault(Exception exception, MessageVersion version, ref Message fault)
{
if (exception.GetType() == typeof(HttpException))
{
var httpException = (HttpException)exception;
var inResponse = WebOperationContext.Current.IncomingRequest;
var webGetAttribute = GetCurrentAttribute(inResponse);
if(webGetAttribute == null)
{
throw new RestException();
}
var currentResponseFormat = webGetAttribute.ResponseFormat;
var restErrorMessage = new RestErrorMessage(httpException.Data, httpException.GetHttpCode(), httpException.ErrorCode);
fault = CreateMessage(restErrorMessage, version, currentResponseFormat);
fault.Properties.Add(WebBodyFormatMessageProperty.Name, GetBodyFormat(currentResponseFormat));
var outResponse = WebOperationContext.Current.OutgoingResponse;
outResponse.StatusCode = (HttpStatusCode)httpException.GetHttpCode();
outResponse.ContentType = string.Format("application/{0}", currentResponseFormat);
}
else
{
throw new RestException();
}
}