See “Connecting BizTalk 2010 to a GVC-LC Vending Machine” to see how this adapter is used. I have recorded all the steps here for my own record of what was done. The custom BizTalk GVCLC LOB adapter sends a poll command to a GVCLC vending machine and waits for a response. The adapter connects to the machine over TCP/IP and starts a communications session. This session can last any length of time.
The socket C# library from Michael Stephenson was used as starting point.
I used the WCF LOB Adapter Development Wizard to create the GVCLC adapter project. I followed the steps from the EchoAdapter example and called the project and the solution GVCLCAdapter. At the welcome screen I supplied a schema of gvclc and a namespace. On the next screen I only ticked synchronous inbound dataflow and all the metadata features. On the next screen I specified the adapter properties as shown below. On the next screen I specified the connection properties as shown below. After pressing next on the summary page I got the expected project solution.
I continued to follow the EchoAdapter example and Michael Stephenson and updated the GVCLCAdapterConnection class.
- I added a field for the socket client and a field that tells us whether we are waiting for a response to send to the socket from BizTalk.
- Next I exposed the SocketClient and isWaitingBTSResponse as a property so they can they can be accessed from the inbound handler class.
- The constructor was modified following Michael Stephenson. In addition I assigned the value of _isWaiting4BTSResponse to false.
- The isvalid class was changed to make sure the adapter was still connectted to the socket.
- The Open method connects the adapter to the socket if the connection no longer exists.
- The Close method was implemented to gracefully shutdown the adapter.
Next i updated the GVCLCAdapterConnectionFactory class by opening the GVCLCAdapterConnectionFactory.cs file. I added the following private fields following Michael Stephenson.
I continued to follow the EchoAdapter example and updated the GVCLCAdapterMetadataBrowseHandler class to implement the GVCLC adapter’s metadata browse.
I continued to follow the EchoAdapter example and updated the GVCLCAdapterMetadataSearchHandler class to implement the IMetadataSearchHandler interface. Inside the Search method I replaced the existing logic in similar manner to he EchoAdapter.
I continued to follow the EchoAdapter example and updated the GVCLCAdapterMetadataResolverHandler class to implement the IMetadataResolverHandler interface . Inside the IsOperationMetadataValid and IsTypeMetadataValid methods I replaced the existing with the following single statement to indicate that every specified type metadata is valid.
Inside the ResolveOperationMetadata method. I replaced the existing logic with the following to resolve the request and response operation. This is different from the EchoAdapter example because the response is now a predefined schema.
CustomGVCLCHonourDenyRespTypeMetadata and CustomGVCLCReqTypeMetadata
The request type metadata class and the response type metadata class was created following the EchoAdapter.
The request XML data definition and the response XML data definition was created. It is much easier if these are all data contacts. See Zhonje for an explanation of why this can be important.
I continued to follow the EchoAdapter example and updated the IInboundHandler interface in the GVCLCInboundHandler class .
added code to the StartListener method to reconnect to the TCP/IP socket if the connection is lost.
I provided the GVCLAdapter implementation for the TryReceive method.
- A poll message is sent to the socket.
- Subsequently the socket is checked for a response by trying the to receive from the socket using the same connection.
- If a “B” or a “N” is received, the adapter sleeps for the polling interval and then another pollong message is sent and the loop starts again.
- A GVCLC message is created if the message is not “B” or “N”.
- The polling stops until a response is received from BizTalk.
I added an implementation for the WaitForMessage method that is the same as in Michael Stephenson ‘s example.
The implementation of the Reply method handles the response from Biztalk back tot he adapter.
- The response is cast to a string using a custom override of the Tostring method on the proxy class that represents the GVCLC response.
- If the string contains a ”C” the response is sent back to the socket.
- Finally the polling of the socket is resumed.
I added an implementation for the Abort method that is the same as in Michael Stephenson ‘s example.
The TimeoutHelper class from the EchoAdapter example was added.
The GVCLC adapter was packaged following Sonuarora