JSON Decoder in custom pipeline is not working - c#

I am using BizTalk+ESB. I send a request to a REST service. Using this pipeline.
Which uses the JSONEncoder. The rest service posts a message in the event log, letting me know the process was completed. The issue is, on the response, I get this error:
"The content type application/json; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)."*
This is the response pipeline:
It acts as if the JSONDecoder is not processing the response message.
The request is made using ESB Itinerary, and a WCF Web Service in BizTalk.
Any suggestions?
UPDATE - The call to the Rest service is in an Itinerary Service. WCF_WebHttp was not in the list of selections. Selected WCF-BasicHttp.
Now I receive the error: "There was a failure executing the response(send) pipeline: "PTwoMapPipeline.Part2RetMapPipeline, PTwoMapPipeline, Version=1.0.1.3, Culture=neutral, PublicKeyToken=7de7b3b357ccad5e" Source: "XML assembler" Receive Port: "WcfReceivePort_WCFInitiator/Service1" URI: "/WCFInitiator/Service1.svc" Reason: The document type "http://schemas.xmlsoap.org/soap/envelope/#Envelope" does not match any of the given schemas."
on the return Pipeline in my receive location. (Two way). Does this mean I need to add an Envelope schema. The Message is set in Receive location to use the body.

You need to use the WCF-WebHttp Adapter for a RESTful service. See WCF-WebHttp Adapter (Microsof.com)
Microsoft BizTalk Server uses the WCF-WebHttp adapter to send messages to RESTful services. The WCF-WebHttp send adapter sends HTTP messages to a service from a BizTalk message. The receive location receives messages from a RESTful service. For GET and DELETE request, the adapter does not use any payload. For POST and PUT request, the adapter uses the BizTalk message body part to the HTTP content/payload.
The WCF-WSHttp is expecting a SOAP envelope and XML see What Is the WCF-WSHttp Adapter? (Microsof.com).
The WCF-WSHttp adapter provides full access to the SOAP security, reliability, and transaction feature

Related

Call to Web Service with ESB Routing Itinerary Service contains no content

I have an Itinerary that is called from a WCF Web Service (WCFService) through BizTalk. The first thing it does is a transformation, using Maps in WCFService. It then routes the response from the mapping to a Rest Service. I created WS-WebHttp adapter to be used with ESB.
The issue is that when it posts to the web service using HttpRequestMessage object, the message does not contain any content. As a test I also routed the transformation to passthough send port as a file and the transformation was correct.
My Itinerary
Here are the settings for the routing service
Routing Service Settings
The content-type is application/json.
I tested it using SOAPUI and it returned the content of the data going in.
Here is the Pipeline on the dynamic send port (request/response)
SendPipelineRequest
I believe I read that an ItinerarySelector is not used in the pipeline, because all the information is handled by the ItineraryCache.
I not sure where the issue is. I assume that the content from the transformation will be in the message passed on by the itinerary. Is there a way I can check this with itinerary before calling the service?
I appreciate the help.
UPDATE: No Content. I was doing a transformation through an itinerary service, instead of the pipeline. once I removed the transformation from the itinerary, and added the map to the incoming receive port, the Rest service receive the content, transformed.

.Net 4. View consumed web service headers and body from request and response

We're consuming a web service (web reference, not service reference), and I need a way to output the entire message being sent (including headers) and the message that gets received.
When I add the web reference, the generated base type of the client object to send the messages is System.Web.Services.Protocols.SoapHttpClientProtocol
I send the messages like so:
ApiService api = new ApiService();
// set the certificate and basic http network credentials
var response = api.SendRequest(messageObject);
I'm able to get the body of the request by serializing messageObject, but can't figure out how to get the full message with the headers.
Since I'm using a certificate and basic authentication, tools like Fiddler, etc. aren't getting me what I need, so I believe I have do something programmatically to pull whats sent and whats received prior to being encrypted with ssl.
EDIT
What I want to see if the data being sent and received to another service from within my WCF service.... e.g.:
// this function is within my WCF service
public ResponseModel Auth()
{
// call to another service here... need to trace this
}
If this is for tracing purposes I have had some success using the tracing capabilities of the System.Net libraries, you should be able to enable the tracing through configuration only.
It's described here: How to: Configure Network Tracing
The resulting log file isn't the easiest to follow, but is described here: Interpreting Network Tracing

How to obtain header values from Client Message Inspector in WCF

I'm creating a web test client for some services I'm working on, and as part of the requirements for that, I would like to be able to display the full request and response SOAP messages (and HTTP headers to the user).
I implemented a MessageInspector class implementing IClientMessageInspector, most notably the BeforeSendRequest and AfterReceiveReply methods to get access to the request & response messages respectively.
Capturing the response (AfterReceiveReply) works great, but capturing the request only partially works. I can access most of the message, however the SOAP header and HTTP headers are both empty. Viewing the request in Fiddler, I can see that WCF is sending a Security header in the SOAP message and "a bunch" of HTTP headers.
My BeforeSendRequest method is very simple...the gist of it is...
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
this.RequestMessage = request.ToString(); // Security header is missing from message
// Try to get HTTP headers
object req; // req is always null
if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out req))
{
this.RequestHeaders = ((HttpRequestMessageProperty)req).Headers;
}
return null;
}
I'm not sure why the HTTP and Security headers are missing. Is there a better way to do this?
Wayne
The inspectors look at the messages right after the message exists the formatter, and before it reaches any of the protocol channels (such as security) which will (potentially) change the message before passing it over (see the diagram in the post about WCF channels at https://learn.microsoft.com/en-us/archive/blogs/carlosfigueira/wcf-extensibility-channels). So at the inspector level you won't be able to find any additional SOAP headers added by the message. The HTTP headers are added by the transport which is also reached after the message passes through the message inspector.
If you want to see all the SOAP headers in the message, you can either create a new "protocol" channel (the sample at http://msdn.microsoft.com/en-us/library/ms751495.aspx does exactly that) or a new message encoder (it can wrap the existing encoder, and inspect the outgoing messages right before they're encoded).
To be able to see the HTTP headers it's harder, since the transport is the last part through which the message passes in WCF. I think you could write a custom transport channel to do that, but that would definitely be a lot of code.

Get SOAP request body in proxy client

I have application which calls a WCF service. For monitoring and tracking purposes I would like to have log all request messages for which application failed to call a service. Loke I need to call operation called RemoveSubscription and once failed(may be network problem or WCF service was down) I would like to log the SOAP message into xml or txt file.
Generaly is it possible to get the request SOAP contact in proxy class.
I found some info that it can be done by extending SoapExtension class. If this is the right way how to register/inject the new class which extends SoapExtension to channel stack.
EDIT : Service is not hosted in IIS it is in Windows service... so I am i right that in this case SoapExtension is not the right solution.
With a WCF based client, you can create an endpoint behavior to intercept the request & response messages. This TechNet article shows how to access the message being sent and the response message. Your WCF client can be generated by either adding a Service Reference in Visual Studio, using SvcUtil to manually generate your client code or rolling your own proxy directly in code using the ChannelFactory class.
Your logging code would always write out the request message with a status of requested and a timestamp to some data store (file, database, etc.) When the response message is received, it would match request message somehow from the response message contents and update the data store to change the status to responded. Selecting all the messages from the data store with the status of requested older that some time period would list all the failed messages.

SOAP action error from AXIS

I'm consuming a Java based Web Service with C# .NET app.
I'm sending a SOAP message in XML format.
But I'm receiving this error message:
ns1:Client.NoSOAPAction no SOAPAction header
You need to look at the WSDL for your service.
The SOAPAction is effectivly the URL you are sending the soap envelope to, so whatever software you are using should set this up in the http headers.

Categories