Wednesday, August 1, 2012

must receive before sending a fault message on an implemented port

As a .net developer , just moved to BizTalk field,  I came across a lot issues in the last couple month when our project start to use BizTalk intensively.

As the title, when I was trying to implement a very simple sample ,  I got this error .

I setup a port which have request/response/fault, refer to the above snapshot.  in my orchestration, I implement very simple logic.
1.receive a message from the request port.
2.read the information from request, and then based on the message type specified in the request, dynamically transform the request to a response message.
3.send the response back to client.
4.if there are any error/exception happens, send a fault back to client.
refer to the following snapshot.
it is quite simple logic , but when I compile it, I get the following two errors.
1.must receive before sending a fault message on an implemented port
2.incomplete requestresponse operation; missing 'send'

By just simply look at the orchestration, I didn't aware anything is wrong, I do have a receive shape at the beginning , also I do have a send shape at the end of the orchestration,thus I refer to my good friend google for answers.  

It is quite hard to find a solution for this easily , I think this might be too easy, too basic, thus no one bother to talk about it.  but I do find some clues, When Visual Studio compile the solution , it will try to make sure every logic path is correct.  Then I go back to visit my orchestration, assume we get an exception in the scope , during the dynamic mapping.  here is the flow. 
1.receive a message from the port. 
2.construct the response message.
3.do the dynamic mapping. here we get an exception.
4.it jump to exception handling.
5.construct fault message
6.send the fault message back to client. 
7 then the flow continue to send a response back. 

You see the issue, after you send a fault message back to client, the whole channel had been faulted, how could we send  a response back client again?

In order to resolve this issue, I simple put a terminate shape after send the fault message back , then it compiles and works smoothly.  The orchestration looks like this.

It puzzled me a while as new BizTalk developer. when you get it , it is so easy.


No comments:

Post a Comment