Print Coding Steps



Great care has been taken to ensure that these XML samples operate as they should. However, these samples are NOT part of the Tech Data XML solution and therefore are NOT supported by Tech Data. The Tech Data Electronic Commerce team is unable to answer questions about these samples. Tech Data makes no guarantees as to their accuracy, currency, content, quality, or availability. These samples are provided "AS IS." By using these samples, you are using them at your own risk. This documentation and the coding samples are provided for your company’s use and may not be distributed. The entire risk arising out of the use or performance of such products and documentation remains with you. In no event shall Tech Data be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the products or documentation, even if Tech Data has been advised of the possibility of such damages.

 

Before Coding Starts

  1. You must obtain, sign and return Tech Data's XML Trading Partner Agreement. This is done with the assistance of the EC Implementations Team.
  2. Communicate your static URLs to the EC Implementations Team, it is a requirement of Tech Data's XML service that users post only from systems with static IP addresses.
  3. The EC Implementations Team will then send you both the test and production URLs.

 

Basic Coding Overview

This section will not cover the programmatic creation of the submit XML document, there are many utilities available in a variety of languages that facilitate this processing. Nor will this section cover the accessing and navigation through the response XML document, again, many utilities and practices are available.

Once the submit document is created the following steps should be taken by your automated process:

  1. If necessary, convert the XML document to a String representation
  2. Establish an HTTP connection to Tech Data's XML service
  3. Set the HTTP's header property "Content-Type" to a value of "text/xml"
  4. Set the HTTP's header property "Content-Length" to the exact length of your submit XML document's string representation
  5. Post the XML document, as a string, through the HTTP connection from step 2 above
  6. Obtain a response stream from the HTTP connection
  7. Receive the response XML document as a string

 


Java Example

The following java code snippet was written under JDK 1.4.2

java.net.URL                        url  =   new java.net.URL( urlStr ); // urlStr is Tech Data's URL as a String
java.net.HttpURLConnection  con =   ( java.net.HttpURLConnection )url.openConnection();

con.setUseCaches( false );
con.setDoOutput( true );
con.setDoInput( true );
con.setRequestProperty( "Content-Type",   "text/xml");
// xmlDocAsStr is the submit XML document as a String
con.setRequestProperty( "Content-Length", "" + xmlDocAsStr.getBytes().length ); 

PrintStream out = new PrintStream( con.getOutputStream() );
out.print( sendText );                // send the submit xml document
out.close();

BufferedReader buffReader = new BufferedReader( new InputStreamReader( con.getInputStream() ) );
StringBuffer      sb              = new StringBuffer();

String inputLine = null;
while ( ( inputLine = buffReader.readLine() ) != null) {
    sb.append( inputLine );    // receive the response xml document
}

// the response XML document is now in sb as a String

out.close();    // ALWAYS close your connection !
con = null;     // This cleanup is best performed in a 'finally' code block
out = null;
con = null;

   


VB.Net Example

The following VB.Net code snippet was written in version 1.1

Dim xmlDocAsStr as String = "..." ' xmlDocAsStr is the submit XML document as a String 

Dim byteArray(xmlDocAsStr.Length - 1) As Byte    
Dim objUTF8Encoding As  New UTF8Encoding
byteArray = objUTF8Encoding.GetBytes(xmlDocAsStr)
 ' urlStr is Tech Data's URL as a String
Dim con As CType(WebRequest.Create(urlStr), HttpWebRequest)   

con.Method = "POST"
con.ContentType = "text/xml"
con.ContentLength = byteArray.Length

Dim strmRequest As con.GetRequestStream()

strmRequest.Write(byteArray, 0, byteArray.Length)    ' send the submit xml document
strmRequest.Close()

Dim srResponse as New StreamReader(con.GetResponse().GetResponseStream(), Encoding.ASCII)

Dim sb as  srResponse.ReadToEnd()  ' receive the response xml document

' the response XML document is now in sb as a String
srResponse.Close()  ' ALWAYS close your connection !

Dim responseXml as String = sb.ToString()


C# Example

The following is a C# code snippet

string xmlDocAsStr = "..."; //  xmlDocAsStr is the submit XML document as a String 

// urlStr is Tech Data's URL as a String
HttpWebRequest myRequest  =     (HttpWebRequest)WebRequest.Create( urlStr );
myRequest.Method               =     "POST";
myRequest.ContentType        =     "text/xml; charset=utf-8";
myRequest.ContentLength     =      xmlDocAsStr.Length; 
Stream sendStream = myRequest.GetRequestStream();
byte[] data              = Encoding.UTF8.GetBytes(xmlDocAsStr);

sendStream.Write(data , 0, data.Length);            // send the submit xml document
sendStream.Close();                                         //  ALWAYS close your connection !

WebResponse myResponse   =     myRequest.GetResponse();
StreamReaderstreamReader =     new StreamReader(myResponse.GetResponseStream());

StringBuilder sb = new StringBuilder();
while (streamReader.Peek() >= 0){
      sb.Append( streamReader.ReadLine() );    // receive the response xml document
}

// the response XML document is now in sb as a String
streamReader.Close();                                  //  ALWAYS close your connection !
myResponse.Close();

string responseXml = sb.ToString();

©(2002, 2003-2007) Tech Data Corporation. All Rights Reserved. Tech Data proprietary and confidential