Use Response of a wcf request as request in another receive port - wcf

Is there any way to use the response of a wcf service method request as an input for the next request in same orchestration and return the response of the first request as well as the response of the second request as out put in BizTalk?
Eg :
My first request gives a response as "a"
Give this response "a" as request to the 2nd request and gets the response as "b"
Return the response as "a" and "b".
Is this possible?

Yes. You could either create a map from Response 1 to Request 2, and also create a multiple input message map from Response 1 and Response 2 to your final output message.
If the messages involved don't have any repeating structures, it may be enough to distinguish the fields that you need to be concerned with and just use a ConstructMessage with an XmlDocument, i.e.
// construct shape code
varXmlDoc = new System.Xml.XmlDocument();
varXmlDoc.LoadXml("<webSvcRequest2 xmlns=''><ParamB>" + msgWebSvcResp1.ParamA + "</ParamB></webSvcRequest2>");
msgWebSvcReq2 = varXmlDoc;
And similar code for producing the final output message. If you go this route, I'd advice creating some C# utility methods to actually store the strings/message templates.

Related

How to check if all status codes are 200 in Mulesoft 4?

Say for example, I created a flow for scatter-gather and I want to check if all endpoints are returning same result status code 200 or throw an error if not.
Configure the Response Validator (General > Response > Response Validator) for each HTTP Request so only 200..299 responses are considered valid.
You can use try block for every HTTP request on wrap whole scatter gather. If one fails, capture HTTP status code in on error propogate and log the results.
I suggest you wrap each request into try block, if you already have a global error handler defined, it should pick up status code 500 etc. Otherwise, capture response code into dataweave

Identify bad requests(4xx response code) from navigator.sendBeacon()

How can I get response code from navigator.sendBeacon? I need to have some indicator that can say me that request is failed? Particularly, I am looking for a way to identify bad request (request that was send with “bad” malformed json and got 4xx response code). Is there any way to do it while using sendBeacon?
From documentation:
The sendBeacon() method returns true if the user agent is able to
successfully queue the data for transfer, Otherwise it returns false.
So, it is not returning false if request is invalid.(and response code is 4xx)
navigator.sendBeacon(that.sushiEndpoint, sushiPayload)

Parsing XML Response In GateWayScript

Hi i am new to API connect ... i have a use case where i have to merge responses coming from two endpoints in XML format based on certain conditions.
My flow in the assemble section is like this
1) INVOKE
(i make my
first service call
and capture the response
in a custom 'Response
object varibale' -XMLResponse1
2) INVOKE
(i make my
second service call
and here i am not using any
custom 'Response object varibale'
Instead i am using apim.getvaribale('message.body') to get the response
3)GATEWAYSCRIPT
Here i want to write my script for parsing the xml and merging the two responses
and send back the merged response to the consumer
I observed that the xml response is not getting captured in a custom Response object variable when i try to capture it like below
var test1= apim.getvariable('XMLResponse1');
test1.item(0).childNodes
it throws me an exception like this
test1.item is not a function
now for the second response like below where i am not capturing the response in a custom Response object variable it works well
var test2= apim.getvariable('message.body');
My question:
1)How do i capture the xml responses in a custom Response object variable?
2)How can i parse the response into a javascript object? are there any libraries supported in api connect?
Below is the samples found from IBM community. Hope this may help you.
**** Sample XML ****
<Routing>
<partner name="Partner A" key="1">
<from_ID>PartnerA-KEY1-INT</from_ID>
<to_ID>PartnerA-KEY1-EXT</to_ID>
<destination>PartnerA-KEY1-DESTINATION</destination>
</partner>
<partner name="Partner B" key="2">
<from_ID>PartnerB-KEY2-INT</from_ID>
<to_ID>PartnerB-KEY2-EXT</to_ID>
<destination>PartnerB-KEY2-DESTINATION</destination>
</partner>
<partner name="Partner C" key="3">
<from_ID>PartnerC-KEY3-INT</from_ID>
<to_ID>PartnerC-KEY3-EXT</to_ID>
<destination>PartnerC-KEY3-DESTINATION</destination>
</partner>
</Routing>
**** Corresponing Gateway Script *****
var response = apim.getvariable('XMLResponse1.body');
var objType = response.item(0);
var string = objType.getElementsByTagName("partner").item(0).getElementsByTagName("from_ID").item(0).textContent;
output ---> string = PartnerA-KEY1-INT
Why do you want to merge them in a GatewayScript node??
You could merge them in a mapping node, in wich you have 2 variables as input (refered to the output objects of your invokes) and one XML object as output...
If you have to apply some conditions or comparisons, you could do them in the code part of the mapping nodes

How to set http response code in Parse Server cloud function?

A parse server cloud function is defined via
Parse.Cloud.define("hello", function(request, response) {..});
on the response, I can call response.success(X) and response.error(Y), and that sets the http response code and the body of the response.
But how do I define a different code, like created (201)?
And how do I set the headers of the response?
thanks, Tim
You are allowed to return any valid JSON from response.success(). Therefore, you could create an object with fields such as code, message, and value, so you can set the code, give it a string descriptor, and pass back the value you normally would, if there is one. This seems to accomplish what you need, though you will have to keep track of those codes across your platforms. I recommend looking up standard http response codes and make sure you don't overlap with any standards.

Accessing the HTTP headers from a WCF Service

I need to access the HTTP response headers that are to be returned to the client from a WCF Service. Accessing the HTTPContext is easy(through HttpContext.Current.Response), but what is the event/extension/behavior that is executed lastly, when the StatusCode is already set (for ex. if the status is 500)?
EDIT: Message Inspectors don't seem to be a good solution here, because at the time they run, the status code isn't set yet. (At least in my trial that was the case)
You can access all headers on WebOperationContext.Current.IncomingRequest, like this:
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
WebHeaderCollection headers = request.Headers;
Console.WriteLine("-------------------------------------------------------");
foreach (string headerName in headers.AllKeys)
{
Console.WriteLine(headerName + ": " + headers[headerName]);
}
Console.WriteLine("-------------------------------------------------------");
See here
Simplest way for having control on the Headers is to use Message contracts.
Use Message Inspectors to monitor the message right after receiving it at the Service end.
In an extreme case, where you are not satisfied with any other standard routes, you can go for POX (Plain Old XML) type operations where you would be dealing with raw XML message.