2

I have a BizTalk 2010 project containing an orchestration that needs to make an HTTP Post and then examine the Status Code and Body of the Response to determine the next course of action.

I can configure the orchestration and port to make the HTTP Post, but I am unable to receive a response.

Should I be using a send / receive port or correlation?

What schema should I be using for the response (I believe the response is the standard http response: http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6).

Matt
  • 23
  • 1
  • 6
  • When you say HTTP post, do you mean sending Xml to a SOAP service, or e.g. a POX or JSON WebAPI call or MVC Controller action, etc? – StuartLC Nov 14 '12 at 10:32
  • It is not xml, it is structured text similar to EDI. – Matt Nov 14 '12 at 10:59
  • @Matt can you post the EDI msg structure – MIkCode Nov 14 '12 at 11:26
  • @Matt - How is your send port configured? When you say you are unable to receive a response, do you mean an error is occurring, or that you don't see the orchestration picking up the response? – BizTalkMama Nov 14 '12 at 15:16
  • @MlkCode, I cannot send the EDI message structure. I am simply trying to perform a post and examine the response status code (and the response body) that is returned in a similar manner to Jugglist answer on http://stackoverflow.com/questions/692342/net-httpwebrequest-getresponse-raises-exception-when-http-status-code-400-ba but using BizTalk. I do not believe the message or service type is relevant. – Matt Nov 16 '12 at 17:10
  • @BizTalkMama, To be honest I have tried several configurations and am at a loss as to how the port should be configured. When I have the port configured as Send only I can perform the POST, I am unable to even configure the Send port as a "Send and Receive" as I do not know the schema a standard http response corresponds to. When I perform the POST using the send port, should I be able to examine the response StatusCode if so how? – Matt Nov 16 '12 at 17:39
  • @Matt - If you haven't already, I would try configuring your logical send port to Send-Receive, and set the type for the response message to XmlDocument just to confirm you can get the response back. Once you confirm you have the communication working properly, you can tweak this config, and inspect the response and grab the status code, as Brett suggests below. – BizTalkMama Nov 19 '12 at 15:43
  • @BizTalkMama - I have configured the response type to XmlDocument as suggested and can view the response body has been received by searching for tracked message events (I have not had any luck converting the Message to XMLDocument variable and outputting the OuterXML as the message is not XML). I have tried Brett's code as suggested but received an error as per http://social.msdn.microsoft.com/Forums/is/biztalkr2adapters/thread/3079bcb7-4b9d-4f8c-a225-3154869a2f87 – Matt Nov 20 '12 at 17:09

2 Answers2

1

If you are looking for a kind of notification ( not in content of the message) that the message has been successfully transmitted, you can set the logical send port property in the orchestration as follows:

"Delivery Notification" = Transmitted

And delivery failures can be handled using the Microsoft.XLANGs.BaseTypes.DeliveryFailureException

kleopatra
  • 51,061
  • 28
  • 99
  • 211
user1826905
  • 558
  • 3
  • 9
  • Thanks for the response, but I am unsure how either of these will allow me to view / extract the http response status code. – Matt Nov 16 '12 at 17:44
  • Checking the HTTP response code and taking action is like implementing the HTTP protocol. Biztalk abstarcts that and provides the 'Delivery Notification' which should be trustworthy enough to accept that the message was sent successfully. For e.g. 200, 201, 202, 204 are all HTTP success response codes. – user1826905 Nov 19 '12 at 10:36
  • The third party service I am trying to connect to returns data in the response body on success (code 200) and error messages in the body for 400-4nn codes. Given the abstraction you mention, is it possible to retrieve the response body and if so how? – Matt Nov 20 '12 at 11:34
  • My suggestion is use another tool like **Fiddler** and POST your data to the URL. Then save the responses from the URL for both success and failure scenario. These I guess will be some kind of flat files or delimited files or there will be some logic in these responses to conver them to a Flat File XSD. Now, you can have a request-response port and on the response you can have your flat file pipeline. You might be better off if you can post the responses you see from the URL. – user1826905 Nov 20 '12 at 15:05
  • Thanks for the suggestion, I will take a look at it tomorrow. I am using a simple test harness to control the responses at this time. – Matt Nov 20 '12 at 17:24
  • If you are interested the raw response output from Fiddler is: HTTP/1.1 200 OK Server: ASP.NET Development Server/10.0.0.0 Date: Tue, 20 Nov 2012 17:20:35 GMT X-AspNet-Version: 4.0.30319 Transfer-Encoding: chunked Cache-Control: private Content-Type: text/html; charset=utf-8 Connection: Close d TEST RESPONSE 0 and HTTP/1.1 400 Bad Request Server: ASP.NET Development Server/10.0.0.0 Date: Tue, 20 Nov 2012 17:22:11 GMT X-AspNet-Version: 4.0.30319 Cache-Control: private Content-Type: text/html Connection: Close TEST RESPONSE – Matt Nov 20 '12 at 17:32
  • Apart from the headers, I guess the body of the response is between **TEST RESPONSE**. Now in order to build a flat file schema for that, you need to be more specific about the line breaks or tabs or any delimiters to extract the fields. Once you have defined your flatfile XSD, its easy to build a pipeline for that and use that in the response part of your request-response port. – user1826905 Nov 21 '12 at 09:19
  • Hope this link guides you in handling your non standard response from HTTP post: [Kent Weare's BizTalk Blog](http://kentweare.blogspot.co.uk/2009/06/adventures-with-http-adapter-and-yahoo.html) – user1826905 Nov 21 '12 at 09:24
  • Thanks for the reply and the the link, I will give it a try. Having not implemented a custom pipeline component before, do you know if the header elements specifically "HTTP/1.1 200 OK Server" will be available along with the response body? – Matt Nov 21 '12 at 10:43
  • As its in the Header, it should not be a part of the response body. You can check the response body in fiddler or by posting the request in a web browser. Whatever the Web browser shows you is the response body. – user1826905 Nov 21 '12 at 11:17
  • Sorry I may have worded the question incorrectly. Is it possible to view the Response Header within a custom Pipeline component, as ultimately I will need to receive both the response status code and the response body within an orchestration – Matt Nov 21 '12 at 11:52
0

The Http Status Code should be available on the Response message as a Context Property, which you can access in an Expression shape.

statusCode = ResponseMessage(HTTP.ResponseStatusCode);

Your ResponseMessage should be of type System.Xml.XmlDocument, but as it won't be a real Xml Document, make sure the Request/Response port is configured to use the PassThruReceive pipeline on the Response side.

Brett
  • 1,127
  • 6
  • 11
  • Thanks Brett, however I am receiving an error "There is no value associated with the property 'HTTP.ResponseStatusCode' in the message." – Matt Nov 20 '12 at 11:22
  • Just for clarity: I have an orchestration sending a simple xml message (test) to a Send-Receive Port. The Request message type matches the schema for the simple message and has the send pipeline configured as XMLTransmit. The Response message type is System.Xml.XMLDocument and the Receive pipeline is configured as PassThruReceive. After the receive shape I have an expression shape with code to write HTTP.ResponseStatusCode to the eventlog. The Send Port is of type HTTP. – Matt Nov 20 '12 at 11:41
  • I have made some progress; using a custom pipeline component on the receive port enables me to see the response body. However the status code and the response description is not contained within. This also has the limitation that only successful messages (status code 200) result in a response being generated. – Matt Nov 23 '12 at 10:26
  • 1
    I also setup a send port to save the ACKS and NACKS for messaages on a one-way send port with the "Delivery Notification" set to "Transmitted". I can see the Response body and the Response Status Code only for NACKs – Matt Nov 23 '12 at 10:30
  • 1
    It appears that using a combination of the two approaches as suggested by user1826905 will resolve the original question. – Matt Nov 23 '12 at 10:54