本文整理汇总了C#中System.Net.Http.HttpResponseMessage.ToMessage方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseMessage.ToMessage方法的具体用法?C# HttpResponseMessage.ToMessage怎么用?C# HttpResponseMessage.ToMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpResponseMessage
的用法示例。
在下文中一共展示了HttpResponseMessage.ToMessage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TraceHttpResponseMessage
private Message TraceHttpResponseMessage(HttpResponseMessage msg)
{
string tracemsg = String.Format(
"Web Response Header: {0}\n" +
"Web Response Body: {1}",
msg,
msg.Content != null ? msg.Content.ReadAsString() : "(empty)");
LoggingHelper.TraceLine(tracemsg, LoggingHelper.LogLevel.Info);
return msg.ToMessage();
}
示例2: TraceHttpResponseMessage
private Message TraceHttpResponseMessage(HttpResponseMessage msg)
{
// response tracing is done in BaseResource.ReturnResult
return msg.ToMessage();
}
示例3: CreateMessage
public Message CreateMessage(HttpResponseMessage httpResponse)
{
var response = httpResponse.ToMessage();
Assert.IsNotNull(response);
return response;
}
示例4: ToMessage_Returns_HttpMessage_With_IsRequest_False
public void ToMessage_Returns_HttpMessage_With_IsRequest_False()
{
HttpResponseMessage response = new HttpResponseMessage();
HttpMessage message = response.ToMessage() as HttpMessage;
Assert.IsFalse(message.IsRequest, "HttpResponseMessage.ToMessage should have returned an HttpMessage instance in which IsRequest is 'false'.");
}
示例5: ToMessage_Returns_HttpMessage_For_HttpResponseMessage
public void ToMessage_Returns_HttpMessage_For_HttpResponseMessage()
{
HttpResponseMessage request = new HttpResponseMessage();
Message message = request.ToMessage();
Assert.IsNotNull(message, "HttpResponseMessage.ToMessage should never return null.");
Assert.IsInstanceOfType(message, typeof(HttpMessage), "HttpRequestMessage.ToMessage should have returned an HttpMessage instance.");
}
示例6: ToHttpResponseMessage_Throws_If_Message_Is_Closed
public void ToHttpResponseMessage_Throws_If_Message_Is_Closed()
{
HttpResponseMessage response = new HttpResponseMessage();
Message wcfResponse = response.ToMessage();
wcfResponse.Close();
ExceptionAssert.Throws<ObjectDisposedException>(
SR.MessageClosed,
() =>
{
wcfResponse.ToHttpResponseMessage();
});
}
示例7: ToHttpResponseMessage_Returns_The_Original_HttpResponseMessage
public void ToHttpResponseMessage_Returns_The_Original_HttpResponseMessage()
{
HttpResponseMessage response = new HttpResponseMessage();
Message wcfResponse = response.ToMessage();
HttpResponseMessage responseRoundTripped = wcfResponse.ToHttpResponseMessage();
Assert.IsNotNull(responseRoundTripped, "Message.ToHttpResponseMessage should not have returned null.");
Assert.AreSame(response, responseRoundTripped, "Message.ToHttpResponseMessage should have returned the orignal instance of HttpResponseMessage.");
}
示例8: ToHttpResponseMessage_Does_Not_Change_Message_State
public void ToHttpResponseMessage_Does_Not_Change_Message_State()
{
HttpResponseMessage response = new HttpResponseMessage();
Message wcfResponse = response.ToMessage();
MessageState state = wcfResponse.State;
wcfResponse.ToHttpResponseMessage();
Assert.AreEqual(state, wcfResponse.State, "Message.State should be the same before and after calling Message.ToHttpResponseMessage.");
HttpResponseMessage responseRoundTripped = wcfResponse.ToHttpResponseMessage();
}
示例9: ToHttpResponseMessage_Can_Be_Called_Multiple_Times
public void ToHttpResponseMessage_Can_Be_Called_Multiple_Times()
{
HttpResponseMessage response = new HttpResponseMessage();
Message wcfResponse = response.ToMessage();
HttpResponseMessage responseRoundTripped = wcfResponse.ToHttpResponseMessage();
Assert.IsNotNull(responseRoundTripped, "Message.ToHttpResponseMessage should not have returned null.");
Assert.AreSame(response, responseRoundTripped, "Message.ToHttpResponseMessage should have returned the orignal instance of HttpResponseMessage.");
HttpResponseMessage responseRoundTrippedAgain = wcfResponse.ToHttpResponseMessage();
Assert.IsNotNull(responseRoundTrippedAgain, "Message.ToHttpResponseMessage should not have returned null.");
Assert.AreSame(response, responseRoundTrippedAgain, "Message.ToHttpResponseMessage should have returned the orignal instance of HttpResponseMessage.");
}
示例10: ToHttpRequestMessage_Returns_Null_For_HttpResponseMessage
public void ToHttpRequestMessage_Returns_Null_For_HttpResponseMessage()
{
HttpResponseMessage response = new HttpResponseMessage();
Message wcfResponse = response.ToMessage();
Assert.IsNull(wcfResponse.ToHttpRequestMessage(), "Message.ToHttpRequestMessage should have returned null.");
}
示例11: BeforeSendReply_Receives_HttpResponseMessage
public void BeforeSendReply_Receives_HttpResponseMessage()
{
HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
Message wcfMessage = httpResponseMessage.ToMessage();
IDispatchMessageInspector inspector = new MockHttpMessageInspector()
{
OnBeforeSendReply = (actualMessage, state) =>
{
Assert.AreSame(httpResponseMessage, actualMessage, "BeforeSendReply did not receive the message we provided.");
}
};
inspector.BeforeSendReply(ref wcfMessage, correlationState: null);
Assert.AreSame(httpResponseMessage, wcfMessage.ToHttpResponseMessage(), "Expected embedded HttpResponseMessage to remain unmodified");
Assert.IsTrue(((MockHttpMessageInspector)inspector).WasBeforeSendReplyCalled, "BeforeSentReply in derived class was not called");
}
示例12: BeforeSendReply_Receives_Custom_CorrelationState
public void BeforeSendReply_Receives_Custom_CorrelationState()
{
HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
Message wcfMessage = httpResponseMessage.ToMessage();
object correlationState = "Hello";
IDispatchMessageInspector inspector = new MockHttpMessageInspector()
{
OnBeforeSendReply = (actualMessage, state) =>
{
Assert.AreSame(correlationState, state, "BeforeSendReply did not receive the state we provided.");
}
};
inspector.BeforeSendReply(ref wcfMessage, correlationState);
Assert.IsTrue(((MockHttpMessageInspector)inspector).WasBeforeSendReplyCalled, "BeforeSentReply in derived class was not called");
}
示例13: ToHttpResponseMessage_Throws_If_Message_Is_Closed
public void ToHttpResponseMessage_Throws_If_Message_Is_Closed()
{
HttpResponseMessage response = new HttpResponseMessage();
Message wcfResponse = response.ToMessage();
wcfResponse.Close();
ExceptionAssert.Throws(
typeof(ObjectDisposedException),
"Message.ToHttpResponseMessage should have thrown because the message is closed.",
() =>
{
wcfResponse.ToHttpResponseMessage();
});
}
示例14: SendResponse
private void SendResponse(RequestContext context)
{
Assert.IsNotNull(context);
// Validate request
var request = context.RequestMessage;
Assert.IsNotNull(request);
var httpRequest = request.ToHttpRequestMessage();
Assert.IsNotNull(httpRequest);
// Create response
var httpResponse = new HttpResponseMessage(HttpStatusCode.OK, BasicChannelTests.ChannelHttpReasonPhrase);
Assert.IsNotNull(httpResponse);
TestServiceCommon.CopyTestHeader(httpRequest, httpResponse);
// Send response
var response = httpResponse.ToMessage();
Assert.IsNotNull(response);
context.Reply(response);
}