0

Similar to this question, I need to send back JSON. WCF ResponseFormat For WebGet

But I'm working from within a WCF Behavior being called by a BizTalk 2010 SendPort Adapter.

I'm inside this method:

public object BeforeSendRequest(ref Message request, IClientChannel channel)

So I have the Message and the channel that I can manipulate.

I think the direction is something like this:

1) //WebOperationContext.Current.OutgoingResponse.ContentType = “text/plain”;

or

2) OperationContext.Current.... something - but I don't know the object model well.

I'm currently using the 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.

My headers have this:

Content-Type: application/json
Accept: application/json
Community
  • 1
  • 1
NealWalters
  • 17,197
  • 42
  • 141
  • 251

1 Answers1

0

I think these are the lines I need, but still testing...

WebBodyFormatMessageProperty bodyFormat = new WebBodyFormatMessageProperty(WebContentFormat.Json);
newMessage.Properties.Add(WebBodyFormatMessageProperty.Name, bodyFormat);

It looks like maybe now I should pass XML and this will cause the serialization to happen? I'm now on to my next error:

System.ArgumentException: Encountered unexpected namespace 'http://schemas.datacontract.org/2004/07/System.IO'. The namespace must be empty.
Parameter name: ns

Going to try "raw":

WebBodyFormatMessageProperty bodyFormat = new WebBodyFormatMessageProperty(WebContentFormat.Json);
newMessage.Properties.Add(WebBodyFormatMessageProperty.Name, bodyFormat);
NealWalters
  • 17,197
  • 42
  • 141
  • 251