HOW TO: Create a BizTalk AIC That Posts to an IIS Server and Processes the Response of the IIS Server (316633)



The information in this article applies to:

  • Microsoft BizTalk Server 2000
  • Microsoft BizTalk Server 2002

This article was previously published under Q316633

SUMMARY

This article describes how to create a BizTalk Application Integration Component (AIC) that sends a document to a trading partner's Internet Information Services (IIS)-based server and writes the IIS server's response to a text file. This scenario may be useful for exchanging business documents with trading partners that do not use Microsoft BizTalk Server.

back to the top

Create a Visual Basic 6.0 Application Integration Component

  1. Start a new ActiveX dynamic-link library (DLL) project in Microsoft Visual Basic 6.0.
  2. Add the following references to the project:
    • Microsoft XML, 3.0 (\Winnt\System32\Msxml3.dll)
    • Microsoft BizTalk Server Application Interface Components 1.0 Type Library (\Program Files\Microsoft BizTalk Server\Btscomplib.tlb)
    • Microsoft Scripting Runtime (\Winnt\System32\Scrrun.dll)
  3. Paste the following code into the class for this project:
    '*******************************************
    'XMLHTTPAIC.cls
    Option Explicit
    Implements IBTSAppIntegration
    Dim responseobj As String
    Dim msg As String
    Dim webserveraddress As String
    Dim objXMLHTTP As New MSXML2.ServerXMLHTTP
    Dim xmldoc As New DOMDocument
    Dim FileSystemObject As New Scripting.FileSystemObject
    Dim ts
    Dim responsetxt As String
    
    Private Function IBTSAppIntegration_ProcessMessage(ByVal bstrDocument As String) As String
        On Error GoTo ExecuteError
     
        SendHTTP bstrDocument
    
        IBTSAppIntegration_ProcessMessage = responseobj
        
        msg = ""
        webserveraddress = ""
        Set objXMLHTTP = Nothing
        Set xmldoc = Nothing
        Set ts = Nothing
        Set FileSystemObject = Nothing
        responseobj = ""
        responsetxt = ""
                
        Exit Function
        
    ExecuteError:
        On Error GoTo 0
        Err.Raise Err.Number, Err.Source, "The following Error was encountered: " + Err.Description
    End Function
    
    Private Function SendHTTP(strData As String)
        xmldoc.loadXML (strData)
        msg = CStr(xmldoc.xml)
        webserveraddress = "http://<servername>/response.asp"
        objXMLHTTP.open "POST", webserveraddress, False
        objXMLHTTP.send msg
        responseobj = objXMLHTTP.responsetext
        xmldoc.loadXML (responseobj)
        responsetxt = xmldoc.documentElement.childNodes(0).Text
        Set ts = FileSystemObject.CreateTextFile("c:\response\" & responsetxt & ".xml", True)
        ts.Write responseobj
        ts.Close
    End Function
    '*******************************************
    					
  4. Create a folder named response on drive C of the BizTalk server.
  5. Modify the webserveraddress variable to point to the name of the trading partner's receiving Web page.
  6. Change the name of the project to BTSAIC.
  7. Change the name of the class to XMLHTTPSend.
  8. Save the project as XMLHTTPAIC.vbp, and then save the class as XMLHTTPAIC.cls.
  9. Create the XMLHTTPAIC.dll file.
  10. Start the Component Services snap-in.
  11. In the console tree, right-click COM+ Applications, click New, click Application, and then click Next.
  12. Create an empty application with the name XMLHTTPAIC as a Server Application, and then click Next.
  13. Under Account, click This user, and then type the user name and password of your BizTalk Service account or of an account that is a member of the BizTalk Server Administrators group.
  14. Click Next, and then click Finish.
  15. Expand the newly created XMLHTTPAIC package, right-click Components, point to New, and then click Component. Click Next.
  16. Click Install new component(s), click Add, and then browse to the XMLHTTPAIC.dll file that you compiled.
  17. Click Next, and then click Finish.

    You have now created the necessary Application Integration Component to post your document from a Messaging Port to your trading partner.
back to the top

Create the Receiving Web Page on a Trading Partner's IIS Server

  1. Paste the following ASP script into Notepad, and then save it to the home directory of the trading partner's IIS server as response.asp:
    <%@ Language=VBScript %>
    <%
    'response.asp
    Dim PostedDocument
    Dim EntityBody
    Dim Stream
    Dim FileSystemObject
    Dim ts
    Dim stResponse
    Dim rnum
    Dim responsedoc
    Dim filesaved
    
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    EntityBody = Request.BinaryRead (Request.TotalBytes )
    Set Stream = CreateObject("AdoDB.Stream")
    Stream.Type = 1						
    Stream.Open
    Stream.Write EntityBody
    Stream.Position = 0
    Stream.Type = 2						
    Stream.Charset = "us-ascii"
    PostedDocument = PostedDocument & Stream.ReadText
    Stream.Close
    
    filesaved = 0
    do until filesaved = 1
    	'generate random number for response document filename and contents
    	Randomize
    	rnum = 	int((9000 * Rnd) + 1000)
    	stResponse = DatePart("m", Now()) & DatePart("d", Now()) & DatePart("h", Now())& DatePart("n", Now())& rnum
    
    	'write document received to incoming directory
    	On Error Resume Next
    	Set ts = FileSystemObject.CreateTextFile("c:\incoming\" & stResponse & ".xml",False)
    	if err.number = 0 then filesaved = 1
    	err.clear
    loop
    
    On Error GoTo 0
    
    ts.write PostedDocument
    ts.close
    	
    'send response document back to initiator
    Set responsedoc = CreateObject("MSXML2.DomDocument")
    responsedoc.loadXML ("<Response><responsetext/></Response>")
    responsedoc.documentElement.childNodes(0).text = stResponse
    Response.Write responsedoc.xml
    Response.Status = "202 Accepted"
    Response.End
    
    PostedDocument = ""
    Set EntityBody = Nothing
    Set Stream = Nothing
    Set FileSystemObject = Nothing
    Set ts = Nothing
    stResponse = ""
    rnum = 0
    Set responsedoc = nothing
    filesaved = 0
    %>
    					
  2. Create a folder named incoming on drive C of the trading partner's IIS server.
back to the top

Create a Channel and Port and Test the AIC

  1. Create a BizTalk Messaging Port with a transport of Application Integration Component. When you are prompted for the Primary Transport, point to the component name that was created when you created the XMLHTTPAIC COM+ application, which should be BTSAIC XMLHTTPSend. Create a Channel bound to this Port.
  2. Use the Direct Integration SDK Sample that is located the following folder to send a document to the Channel that you created:

    \Program Files\Microsoft BizTalk Server\SDK\Messaging Samples\DirectIntegration\EXE\DirectIntegration.exe

Result:

The Response.asp page on the trading partner's IIS server should write the business document to the C:\Incoming folder of the IIS server. The XMLHTTPAIC AIC should write the IIS server's response document into C:\Response folder on the BizTalk server.

back to the top

Modification Type:MajorLast Reviewed:6/4/2003
Keywords:kbhowto KB316633 kbAudDeveloper