【发布时间】:2016-12-25 14:25:14
【问题描述】:
与这个问题类似,我需要发回 JSON。 WCF ResponseFormat For WebGet
但我正在从 BizTalk 2010 SendPort 适配器调用的 WCF 行为中工作。
我在这个方法里面:
public object BeforeSendRequest(ref Message request, IClientChannel channel)
所以我有我可以操纵的消息和频道。
我认为方向是这样的:
1) //WebOperationContext.Current.OutgoingResponse.ContentType = “text/plain”;
或
2) OperationContext.Current.... 一些东西 - 但我不太了解对象模型。
我目前正在使用 MemoryStream:
byte[] byteArrayJSON = Encoding.UTF8.GetBytes(strJSON);
MemoryStream memStreamJSON = new MemoryStream(byteArrayJSON);
//WebOperationContext.Current.OutgoingResponse.ContentType = “text/plain”;
Message newMessage = Message.CreateMessage(MessageVersion.None, "", memStreamJSON);
...
request = newMessage; // substitute my new message for the original one.
我的标题是这样的:
Content-Type: application/json
Accept: application/json
【问题讨论】: