Unable to programmatically set Content-Type in BizTalk Wcf-Custom response port - wcf

I am attempting to receive JSON messages into BizTalk using the bLogical REST Start Kit for BizTalk (http://biztalkrest.codeplex.com/).
I am able to successfully receive a message, transform it, and return a response from my Orchestration, but when I transform the response back out through the BizTalkRESTResponseHandler, the HTTP Content-Type is being forced back to 'application/xml', even though I'm explicitly setting it to 'application/json'. The Content-Type is confirmed by tracing the Request and Response in Fiddler, as well as SoapUI.
The Accept: value on the Request is 'application/json'
Any ideas how I can trace further into the Wcf-Custom adapter stack to see where the Content-Type is being reset?

You can solve this by adding a HttpResponseMessageProperty before returning the message in the IDispatchMessageInspector. You can either do this directly in the BizTalkRESTResponseHandler IDispatchMessageInspector or in a separate one.
To do it in the BizTalkRESTResponseHandler get the source and add the following 3 lines of code in the BeforeSendReply method just above the "reply = newReply" in the end.
HttpResponseMessageProperty prop = new HttpResponseMessageProperty();
newReply.Properties.Add(HttpResponseMessageProperty.Name, prop);
prop.Headers.Add("Content-Type", "application/json;charset=utf-8");
Now instead of getting:
You will get this:

Related

What are the actual request headers sent in the Intellij HTTP client?

IntelliJ has an HTTP client. When composing a file that is interpreted by the HTTP client, you can specify headers that go out to the server with the request, like so:
###
GET https://{{hostname}}/{{path}}
Content-Type: application/json
X-Auth-Token: {{x-token}}
I want to find the actual value of the token that was used to replace the variable name, seen above as {{x-token}}, but I don't see any way to obtain the request headers. The response headers are obviously available, but not the request headers. See the image below for the test results that are shown after running the HTTP client inside Intellij:
Is there a way to display the REQUEST headers?
Link to IntelliJ Documentation - HTTP Client -- the documentation seems to never mention the actual request headers that are sent over the wire, but they do discuss how to define request headers in composing the .http file type.
Check the Tools | HTTP Client | 'Show HHTP Requests History' action.

WCF SOAP Service Gzip encoding with Custom Binding

Need help in sending a request which is for WCF service. The service has Custom Binding ( The request is Binary encoded).
Initially i was getting the HTTP/1.1 415 Cannot process the message because the content type 'application/soap+xml;charset=UTF-8;action="Phase"' was not the expected type 'application/soap+msbin1+gzip'.
So I manually added a header Content-Type = 'application/soap+msbin1+gzip'. Now the previous error was gone. but now I am getting the following error: "The remote server returned an error: (400) Bad Request"
I am using HttpWebRequest.
Below images for the reference
Code image
Error line Where i got 400

Hosting the endpoint in the BizTalk process using non UTF-8 encoding

There is a problem with encoding using WCF detailed described here : blog post
WCF: Text Message Encoding and ISO-8859-1 Encoding
I'm getting similar error in response :
A message sent to adapter "WCF-BasicHttp" on send port "XXXX" with URI "http://XXXXXXXX:8080/index.php" is suspended.
Error details: System.ServiceModel.ProtocolException: The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.
I'd like to create a simple proxy WS in BizTalk Environment. I created 1 Receive Location using WCF-BasicHttp / WCF-Custom (neither worked) adapter and send port (SOAP WCF-BasicHttp). Send port is subscribing Receive Location as mentioned here:
Best approach to simple proxy on BIZTALK
I created endpoint in the BizTalk process mentioned here: Codit Blog Hosting WCF HTTP receive location inside BizTalk, without using IIS.
I cannot set other textEncoding than UTF-8, while trying to set ISO-8859-1 I get the error:
"The text encoding ISO-8859-1 used in the text message format is not supported. Parameter name: encoding"
Is there any way to run this using some custom encoders in BizTalk environment?
I managed to do it myself.
I deleted textMessageEncoding binding from Receive and Send WCF-Custom adapter
and instead of it I put customMessageEncoder binding with soap11 and proper iso encoding. Note that httpTransport should be last on binding list.

Unable to Pull Message off Queue

Let me explain my configuration:
ActiveMQ 5.12.0
AnyPoint Studio 5.2.1
Mule 3.6.1
Flow of application:
I am using FunctionalTestCase to post and retrieve a message from queue.
MuleClient client = muleContext.getClient();
String productAsJson = "{\"name\":\"Widget\", \"price\":9.99, \"weight\":1.0, \"sku\":\"abcd-12345\"}";
client.dispatch("http://localhost:8081/products", productAsJson, null);
MuleMessage result = client.request("jms://products", RECEIVE_TIMEOUT);
What is happening is the message is getting posted but when I try to retrieve it, I get the string "{NullPayLoad}".
After stepping back through the flow, I have discovered the message payload, when using the Mule Client, is not making the queue. While looking through the admin console for ActiveMQ, I discovered the message details is "{NullPayload}". When I check using the Advance Risk Client, the JSON message is getting posted correctly.
Any suggestions would be greatly appreciated.
Russ
It's NullPayload when using the MuleClient because by default the http operation will be GET and wont be expecting a body to parse.
The MuleClient is more suited to working with Mule transport infrastructure such as the JMS transport or the old http transport. I don't think it plays nice with the new http listener module.
Normally with the transports you can set the method via a property but that doesnt seem to work with the http:listener:
MuleMessage message = getTestMuleMessage();
message.setPayload(productAsJson);
message.setProperty("http.method", "POST", PropertyScope.INBOUND);
client.send("http://localhost:8089/products", message);
I would suggest using a standard HTTP client such as Apache HTTP client etc. and set the method to POST/PUT or whatever method you need to use that expects a body.

Access to request HTTP headers in custom WCF MessageEncoder

Does anyone know how to get access to request HTTP headers within MessageEncoder.ReadMessage method?
It seems that WCF already "knows" request headers at the point of invoking ReadMessage method, at least Content-Type and Content-Length but I cannot get the access to the Content-Encoding header.
Basically, I'm trying to utilize gzip de/compression for WCF service (http://msdn.microsoft.com/en-us/library/ms751458.aspx) and would like to check if decompression is necessary for incoming request. To do that I'd like to check Content-Encoding header but cannot figure out where to get it.
Any ideas?
Thanks!
Here's an answer I gave in another thread which explains how you would need to manipulate the headers via the WebOperationContext in another IOperationBehavior which is coupled with the MessageEncoder.