I had a few people contact me regarding this issue. The site went live not long after my first post. I never followed up with the resolution. Many years later I took a snippet of the code and pasted it below. It has been a long time since I worked on a punch-out site, so hopefully the code here can help some folks. The code is VB.NET, and today I work in C# and my coding style has changed much since the days of this code... this is my disclaimer.
Anyway, this is code from a shopping cart page and a check out page. Just in summary. After the user adds items to the cart and is ready to check out I build a session variable with XML. Then server.redirect the user to another page. That page pulls the XML from the session, response.clears the request, writes the new page from the XML session object that has the Ketera XML, and posts to Ketera... then a response comes back... and you know the rest. All login codes and urls have been changed to protect the innocent. 
--------------------------------
1. Page Shopping Cart Page
--------------------------------
Created XML that will post to Ketera
Private Sub BtnLiveCheckOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLiveCheckOut.Click
Dim strURL As String = Session("PostCartToURL")
Dim ErrorTest As Boolean = False
Try
Create_PostForm_CartCXML("FormCXML", strURL, "Post")
Server.Transfer("Checkout.aspx")
Catch ex As Exception
ErrorTest = True
Session("EmailType") = "HTML"
Session("DBError") = "Error Posting Cart to Ketera"
Session("ITSource_Error") = ex.Message & " Catch All Error CheckOut.aspx: " & ViewState("ErrorMsg")
End Try
If ErrorTest = True Then
Server.Transfer("dbErrorPage.aspx")
Else
Server.Transfer("Checkout.aspx")
End If
End Sub
'====================================================================================================
' Create the HTML FORM to Post to Ketera & The CXML for thier cart.
'====================================================================================================
Sub Create_PostForm_CartCXML(ByVal strFormName As String, ByVal strURL As String, ByVal strMethod As String)
Dim cXML_Form As String = ""
'Build The Post Shopping Cart cXML
'---------------------------------------------------------------
'1. javascript to submit the form
'---------------------------------------------------------------
cXML_Form = cXML_Form & "<HTML>" & vbCrLf
cXML_Form = cXML_Form & "<HEAD>" & vbCrLf
cXML_Form = cXML_Form & "<script type='text/javascript' language='javascript'>" & vbCrLf
cXML_Form = cXML_Form & " function SubmitForm(){" & vbCrLf
cXML_Form = cXML_Form & " document.FormCXML.submit();" & vbCrLf
cXML_Form = cXML_Form & " }" & vbCrLf & vbCrLf
cXML_Form = cXML_Form & " </script>" & vbCrLf
cXML_Form = cXML_Form & "</HEAD>" & vbCrLf & vbCrLf & vbCrLf
'----------------------------------------------------------------
'1. Get the CXML for the form. Do not use URL Encoding
'----------------------------------------------------------------
'Dim strCXML As String = Server.UrlEncode(Build_CXML()) 'Encoded
Dim strCXML As String = Build_CXML()
'----------------------------------------------------------------
'2. Build the form
'----------------------------------------------------------------
'Submit the form when the page loads <body onload="dothis()">
cXML_Form = cXML_Form & "<BODY onload='SubmitForm();'> " & vbCrLf
'<form method="POST" name="frmFirstPage" action="http://localhost/CNF/Test.aspx">
cXML_Form = cXML_Form & "<FORM method='" & strMethod & "'" & " name='" & strFormName & "'" & " action ='" & strURL & "'>"
'----------------------------
'3.Put CXML data here
'----------------------------
'<input type="hidden" name="FirstName" Value='Data Here'">
cXML_Form = cXML_Form & "<input type='hidden' name='" & "cXML-urlencoded" & "'" & " Value='" & strCXML & "'>"
'End of the form
cXML_Form = cXML_Form & "</FORM>" & vbCrLf & vbCrLf & vbCrLf
cXML_Form = cXML_Form & "</BODY>" & vbCrLf
cXML_Form = cXML_Form & "</HTML>" & vbCrLf
'Hold it and create the form in the next page.
Session("cXML_Form") = cXML_Form
End Sub
'==============================================================================
' Build the detail lines for the CXML Submit Form
'==============================================================================
Function Build_CXML() As String
Dim sp As New Spider
Dim strURL As String
Dim PayloadID As String = Session("PayloadID")
Dim strCartTotal As String = Session("CartTotal")
Dim TimeStamp As String = Session("TimeStamp")
Dim BuyerCookie As String = Session("BuyerCookie")
Dim PostToKeteraURL As String = Session("PostCartToURL")
Dim Cust_AddressID As String = Session("Cust_AddressID")
'--------------------------------------------
'1. Delete all shopping cart related rows,
' then insert updated cart.
'--------------------------------------------
Delete_ShoppingCart_Rows()
'------------------------------------
'2. Save this session info to the DB
'-----------------------------------
CreateUser_TrackingTable(BuyerCookie, PayloadID, TimeStamp, PostToKeteraURL, Cust_AddressID)
'--------------------------------
'3. Get the Header for the CXML
'--------------------------------
Dim strPath As String = Server.MapPath("./XML_Templates/Punchout_Header_Create.txt")
Dim CXML_Header As String
'Dim CreateOrEdit As String = Session("CreateOrEdit") 'create' 'edit'
CXML_Header = sp.GetHTML(strPath)
CXML_Header = Replace(CXML_Header, "@@TimeStamp", TimeStamp)
CXML_Header = Replace(CXML_Header, "@@PayLoadID", PayloadID)
CXML_Header = Replace(CXML_Header, "@@ArrowDUNS", "99999992")
CXML_Header = Replace(CXML_Header, "@@KeteraID", "AN099999999") '>> PROD ID
'CXML_Header = Replace(CXML_Header, "@@KeteraID", "AN088888880-T") '>> TEST ID
CXML_Header = Replace(CXML_Header, "@@BuyerCookie", BuyerCookie)
CXML_Header = Replace(CXML_Header, "@@TOTAL", strCartTotal)
CXML_Header = Replace(CXML_Header, "@@Shipping", "0")
CXML_Header = Replace(CXML_Header, "@@Tax", "0")
'CXML_Header = Replace(CXML_Header, "@@CreateOrEdit", CreateOrEdit)
CXML_Header = Replace(CXML_Header, "@@CreateOrEdit", "edit")
'-----------------------------------------
'4. Build the Detail Lines & Save to SQL
'-----------------------------------------
Dim CXML_DetailHold, CXML_Detail, CXML_Detail_Accum As String
strPath = Server.MapPath("./XML_Templates/PunchOut_Detail_Create.txt")
CXML_DetailHold = sp.GetHTML(strPath)
Dim ds As DataSet = Session("dsCart")
Dim row As DataRow
Dim strCriteria As String = "GroupNumber > 0 "
Dim strSortOrder As String = "GroupNumber asc"
Dim aRows As DataRow() = ds.Tables("Garments").Select(strCriteria, strSortOrder)
'Get each garment row and build the CXML
For Each row In aRows
'Reset it to the CXML with the @@Fields.
CXML_Detail = CXML_DetailHold
CXML_Detail = Replace(CXML_Detail, "@@QTY", row("QTY"))
CXML_Detail = Replace(CXML_Detail, "@@GroupPartID", row("GroupItemNumber"))
CXML_Detail = Replace(CXML_Detail, "@@JDEItemNumber", row("JDEItemNumber"))
CXML_Detail = Replace(CXML_Detail, "@@UnitPrice", row("Price"))
Dim Desc As String = Replace(row("ItemDescription"), "'", "")
Desc = Trim(Desc) & " #" & row("JDEItemNumber")
CXML_Detail = Replace(CXML_Detail, "@@Description", Desc)
CXML_Detail = Replace(CXML_Detail, "@@UOM", "EA")
CXML_Detail = Replace(CXML_Detail, "@@Shipping", "0")
CXML_Detail = Replace(CXML_Detail, "@@Shipper", "")
'Accumulate all the detail to return to the form.
CXML_Detail_Accum = CXML_Detail_Accum & CXML_Detail
'--------------------------------------------------
' SQL SERVER: Save Garment Shopping Cart.
'--------------------------------------------------
Save_Garments_To_SQLSERVER(BuyerCookie, row("GroupNumber"), row("GroupItemNumber"), row("ProductType"), row("SubType"), row("JDEItemNumber"), row("SKU"), row("ItemDescription"), row("Color"), row("Size1"), row("Size2Display"), row("Size2Real"), row("Qty"), row("Price"), row("ExtPrice"))
'--------------------------------------------------
'5. Accumulate all the CXML for the emblems
'--------------------------------------------------
CXML_Detail_Accum = CXML_Detail_Accum & Get_Emblems(BuyerCookie, row("GroupNumber"), CXML_DetailHold)
Next row
'-----------------------------------------
'6. Get the trailer, then submit the form
'-----------------------------------------
Dim CXML_Trailer As String
strPath = Server.MapPath("./XML_Templates/PunchOut_Trailer_Create.txt")
CXML_Trailer = sp.GetHTML(strPath)
'----------------------------------------------------------------------
'7. Return the CXML to the calling sub to add it to the form variable
'----------------------------------------------------------------------
Dim CXML_Complete As String = CXML_Header & vbCrLf & CXML_Detail_Accum & vbCrLf & CXML_Trailer
Return CXML_Complete
End Function
--------------------------------
2. To Post to Ketra....
--------------------------------
-- Performed a server redirect to another page. That page cleared the response then wrote the Punchout XML to the response.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cXML_Form As String
cXML_Form = Session("cXML_Form")
'Cls_HELP.SendEmail("CXML Form", cXML_Form)
'Create the form to post back
Response.Clear()
Response.Write(cXML_Form)
Session.Abandon()
End Sub
------------------------------------------------------------------------
3. These snippets are code for reading the response from Ketera. They
send a Binary Stream not clear XML Text
------------------------------------------------------------------------
Sub Post_Response()
Dim strMsg As String
'Sample of the cXML Code.
' <?xml version="1.0" ?>
' <!DOCTYPE cXML (View Source for full doctype...)>
'- <cXML payloadID="20099999999999999999999@172.99.999.9" timestamp="1011118540" version="1.1.009">
' - <Response>
' <Status code="200" text="success" />
' - <PunchOutSetupResponse>
' - <StartPage>
' <URL>http://www.supplier.com/web/index.php?b2b_session=155556674</URL>
' </StartPage>
' </PunchOutSetupResponse>
' </Response>
' </cXML>
'----------------------------------------------------------------------------------
' Create the XML to post to Ketera.
'----------------------------------------------------------------------------------
Dim BuyerCookie As String = Session("BuyerCookie")
If Len(BuyerCookie) = 0 Then
Session("ErrorMsg") = "No buyer Cookie - Post Response Sub"
Session("StatusCode") = "406"
End If
'----------------------------------------------------------------------------------
' Create the XML to post to Ketera.
'----------------------------------------------------------------------------------
Dim strPayLoadID As String = Session("PayloadID")
Dim strTimeStamp As String = Session("TimeStamp")
Dim strCXML As String
'----------------------------------------------------------------------------------
' Form to submit the CXML to Ketera
'----------------------------------------------------------------------------------
Dim strHTML As String = ""
Dim strjava As String = ""
Dim strKeteraURL As String = Session("PostCartToURL")
'----------------------------------------------------------------------------------
'Format cXML. It will be placed in the hidden form field in the next step
'----------------------------------------------------------------------------------
'A. Create the URL
Dim strMySiteURL As String
Dim StatusCode As String = Session("StatusCode")
If StatusCode <> "200" Then
'Give Ketera this ERROR URL
strMsg = Session("ErrorMsg")
Cls_HELP.SendEmail("Punchout Error - Status Code <> 200!", strMsg)
strMySiteURL = "https://www.MySite.com/CNF/dBErrorPage.aspx=?ErrorMsg=" & Server.UrlEncode(strMsg)
Else
'Give Ketera this GOOD URL
strMsg = "success"
strMySiteURL = "https://www.MySite.com/CNF/SetupRequest.aspx?BuyerCookie=" & BuyerCookie
End If
'Dim UTF8 As New UTF8Encoding
'strMySiteURL = Server.UrlEncode(strMySiteURL)
'B. Create the cXML
strCXML = strCXML & "<?xml version=" & """" & "1.0" & """" & "?>" & vbCrLf
strCXML = strCXML & "<!DOCTYPE cXML SYSTEM " & """" & "http://xml.cxml.org/schemas/cXML/1.1.009/cXML.dtd" & """" & ">" & vbCrLf
strCXML = strCXML & " <cXML payloadID=" & """" & strPayLoadID & """" & " timestamp=" & """" & strTimeStamp & """" & ">" & vbCrLf
strCXML = strCXML & " <Response>" & vbCrLf
strCXML = strCXML & " <Status code=" & """" & StatusCode & """" & " text=" & """" & strMsg & """>" & " </Status>" & vbCrLf
strCXML = strCXML & " <PunchOutSetupResponse> " & vbCrLf
strCXML = strCXML & " <StartPage>" & vbCrLf
strCXML = strCXML & " <URL>" & strMySiteURL & "</URL>" & vbCrLf
strCXML = strCXML & " </StartPage>" & vbCrLf
strCXML = strCXML & " </PunchOutSetupResponse>" & vbCrLf
strCXML = strCXML & " </Response>" & vbCrLf
strCXML = strCXML & "</cXML>" & vbCrLf
Response.Write(strCXML)
'Cls_HELP.SendEmail("After Response Write", strCXML)
Exit Sub
End Sub
'-----------------------------------------------------------------------------------------------
' Get the input data stream, it is not a form post, but a binary data stream.
'-----------------------------------------------------------------------------------------------
Function ReturnStream() As String
'MSDN Version of this code.
'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpRequestClassInputStreamTopic.asp
'This is a long verision.
'http://www.eggheadcafe.com/articles/20030813.asp
Dim str As Stream, strmContents As String
Dim counter, strLen, strRead As Integer
' Create a Stream object.
str = Request.InputStream
' Find number of bytes in stream.
strLen = CInt(str.Length)
' Create a byte array.
Dim strArr(strLen) As Byte
' Read stream into byte array.
strRead = str.Read(strArr, 0, strLen)
strmContents = System.Text.Encoding.UTF8.GetString(strArr)
Return Server.UrlDecode(strmContents)
End Function