The next section walks you through the steps of sending a transaction to FedEx using the Ship ManagerDirect tool. Unlike the Ship Manager API, Ship Manager Direct does not require that any particular ware be installed on your computer. However, Ship Manager Direct is very complicated to work withcompared to the XMLWeb services you have learned about in earlier chapters, and it takes significantlymore time to implement in your programs. If you prefer to use the Ship Manager API instead, you must first download the Ship Manager APIsoftware to install on your computer. FedEx offers sample code in a variety of programming languagesto illustrate how to use the Ship Manager API. Please consult the FedEx Web site for more details. Submitting Transactions Using FedEx Ship Manager DirectIn general, you must take the following steps to submit a transaction using the FedEx Ship ManagerDirect tool: 1.Format a transaction in the manner described in the FedEx Ship Manager API User s Guide. 2.Put the transaction into an HTTPPOST request containing the following: POST /GatewayDC HTTP/1.0Referer: YourCompanyNameHost: FedExSSLHostURLAccept: image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */* Content-Type: image/gifContent-length: LengthOfYourFedExTransactionYourFedExTransaction3.Each line should be followed by one new line character except for the Content-length line FedEx transaction line. Two new line characters should follow the Content-length line, new line characters should follow the YourFedExTransaction line. 4.The FedExSSLHostURLis provided to you by FedEx when you contact Web support to requesttest setup. 5.Open an SSLconnection to FedEx. 6.Send the transaction to FedEx using a SSLconnection. 7.Receive and process the response to see any errors. The following Visual Basic .NET code segment illustrates submitting a track request (a 402 transaction) to FedEx. Dim APITrans As String specify the Fed Ex Transaction details to track a particular package Consult the Fed Ex documentation for exact syntaxAPITrans = 0, + Chr(34) + 402 + Chr(34) + 29, + Chr(34) + YourFedExTrackingNumber + Chr(34) + 99, + Chr(34) + Chr(34)
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services
If you prefer to use the Ship Manager Direct service so you do not have to install any software on yourcomputer, you should click the Register link under the FedEx Ship Manager Direct section. Aregistra- tion form similar to the one shown in Figure 7-8 is then displayed. Figure 7-8Scroll down to the data input fields and fill in the information. If you are performing work for a cus- tomer, you are prompted to specify your customer s FedEx account number. After completing the regis- tration process, you have access to the online documentation for the service that you want to use. Before you can use any of the Web API services, you must send an e-mail to the FedEx e-mail addressspecified in the documentation with a sample portion of your code. The code does not have to be work- ing, but FedEx just wants to see that you are serious. They then set you up with access to the test envi- ronment within 24 48 hours. Unfortunately, at this point, you still do not have everything you need in order to submit transactions toFedEx. You must also send a Subscribe request transaction containing your account number and contactinformation to obtain a meter number that is used in later transactions. The response transaction con- tains your assigned FedEx Meter Number. The exact syntax of the Subscribe request transaction and allother transactions can be found in the FedEx online document called FedEx Tagged TransactionListing. One way in which you can submit a transaction is described in the section that follows. 174Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services
which allows you to interact with the FedEx functions by submitting XMLdocuments. Unlike the APIs, Ship Manager Direct does not require that you install any software before using it. Please note that cases, both Ship Manager API and Ship Manager Direct are referred to generically as the ShipManager API. Setting Up a FedEx Developer AccountBefore you can use the FedEx APIs or the Ship Manager Direct service, you must first set up a developeraccount. The process is a bit confusing, so I ll walk you through it here to save you a lot of time. Forstarters, you must have a FedEx account before you can register for a developer account. You can use for your company or take out a personal one in your own name. Assuming you already have a FedEx account, you can sign up for a developer account by visitinghttp://www.fedex.com/us/solutions/wis/index.html/, as shown in Figure 7-7. Figure 7-7173Other
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services
Run the program from Visual Studio .NET, and you see XMLresults similar to the following in a mes- sage box. < ?xml version= 1.0 ?>
UPS Example 1.0001 1 Success 596R6V
927 SW 22ND ST FORT LAUDERDALE FL
33315 US
10368 Steeplebush Court NOBLESVILLE IN
46060 US
0022ND DAY AIR …portions omitted… See how easy it is to interact with the UPS API. To call different methods of the UPS API, you simplyvary the XMLcode accordingly, and then use code similar to the previous to post the XMLdocument toUPS and process the response. The FedEx APIsFedEx offers a number of solutions for incorporating FedEx functionality into your programs. FedExcurrently offers a Ship Manager API and a Return Manager API. The FedEx Ship Manager APIallowsyouto integrate FedEx shipping, tracking, and rate estimation into your programs. The FedEx ReturnManager API allows you to automate the returns process and integrate with your internal systems. These FedEx APIs require that a software program with the necessary DLLs be loaded onto your com- puter before the features can be used. This is not the same as the Web service APIs that you have beenexploring throughout this book so far. Recently, FedEx has released what it calls Ship ManagerDirect172Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services
UPS Example 2 1.0001 Track none YourReferenceNumber Let s look at a Visual Basic .NET example to see how this works. This example tracks a particular pack- age. Create a new Windows Application and paste the code that follows in the Form1_Loadevent procedure. Dim web As New System.Net.WebClientDim strXML As StringstrXML = < ?xml version= 1.0 ?> & _
& _ YourLicenseNumber & _ YourUserId & _
YourPassword & _ & _ < ?xml version= 1.0 ?> & _
& _ & _
& _ UPS Example & _ 1.0001 & _ & _ Track & _ activity & _ & _
YourTrackingNumber & _ add the xml string to the byte arrayDim d As Byte() = System.Text.Encoding.ASCII.GetBytes(strXML) call the UPS api and pass the byte array containing the XML stringDim res As Byte() = _ web.UploadData( https://www.ups.com/ups.app/xml/Track , POST , d) display the results in a message boxMsgBox(System.Text.Encoding.ASCII.GetString(res)) You must specify your own login credentials and your own tracking number on the lines of code wherespecified.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services
Adeveloper key will be e-mailed to you whichyou should save for later use. The developer key enablesyou to access the online documentation. To access the APIs you need an access key. Next, select the GetAccess Key link in the left-hand navigation page, and then specify the type of access key you want toobtain (HTMLor XMLAccess Key). Select XMLAccess Key in order to work with the XMLexamples inthe following section. You are prompted to enter your developer key and provided with an access keythat can be used in your calls to the Web API. Submitting a Request to the UPS APIThe UPS Web API can be accessed by posting HTMLor XMLdocuments to the specified UPS Webaddress, such as https://www.ups.com/ups.app/xml/Track. You learned in prior chapters, such asChapter 5, how to use HTTP-POST to submit an XMLdocument for processing to a Web service. Thesame techniques can be applied to working with the XMLversion of the UPS API. One difference in theUPS API is that you must submit two different XMLdocuments for each call to the API. The first XMLdocument contains the credentials for accessing the service, such as: < ?xml version= 1.0 ?> YourLicenseNumber YourUserId
YourPassword The second XMLdocument contains details about the service to call, such as the following example thatperforms a Track request. < ?xml version= 1.0 ?>
UPS Example 1.0001 Track activity
YourTrackingNumber Because XMLis simply text, you can post both XMLdocuments together as part of the same text string. Here is another example showing both XMLdocuments listed together. This example illustrates how tolocate shipment activity by a reference number. < ?xml version= 1.0 ?>
YourLicenseNumber YourUserId
YourPassword < ?xml version= 1.0 ?>
170Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services
Figure 7-5Copyright 2005, United Parcel Service of America, Inc. Figure 7-6Copyright 2005, United Parcel Service of America, Inc.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
13.If the submission was successful, you receive the fax at the specified fax number within a shorttime period. See how easy it is to send a fax using the InterFax Web service! On your own, you can modify the previ- ous example to implement features that allow the user to browse for and specify the file to send and thefax number to send the fax to (which should be your developer fax number if you re using the developeraccount). For more information about the methods available from the InterFax Web service, please visit theInterFax Web site at www.interfax.net. Another example of a free faxing Web service can be found at http://www.webservicex.net/WS/ WSDetails.aspx?CATID=4&WSID=7. WebserviceX.Netoffers a variety of Web services. The SendFaxmethod is free to use, but currently appears to allow you to send only text faxes and not file attachments. The UPS APIUPS has several tools available for integration. TheUPS OnLine Tools available at ups.ec.comare foruse by an end user. An end user incorporates the tools into their business s e-commerce-enabled applica- tions that are not available for commercial sale. Third-party developers such as web developers, systemintegrators, or IT consultants that integrate UPS OnLine Tools for end users must register as a thirdparty. The same holds true for an independent software vendor or application service provider that inte- grates the tools into their software application(s) for direct or indirect sale to the public. UPS requires aseparate third party developer license agreement and product certification by an outside test lab forthose applications for sale to the public. If you are interested in licensing UPS OnLine(r) Tools as anThird Party, you need to submit your request to UPS using the Third Party Product Provider LicenseRequest (http://www.ec.ups.com/ecommerce/gettools/prodcompanies.html). Before you can use the UPS API, you must set up a developer account and obtain access keys. Let s walkthrough the registration steps, and then you can use the API to track a package programmatically. Setting Up a UPS Developer AccountThe first step in setting up a developer account involves navigating to http://www.ec.ups.com/ ecommerce/gettools/gtools_intro.html. Ascreen similar to the one shown in Figure 7-5 is displayed. Click the Register link. You are prompted to accept the terms of the UPS license agreement. You thenneed to fill in the registration information, including a username and password. Upon successful regis- tration, you are directed to the online documentation. At this point, you still have not completed creation of a developer account. Select Get Tools from thenavigation pane, and on the page that says Choose your UPS online tool, select the type of tool youwant to use (rate tracking, and so on). You are prompted to accept the Developer agreement. You arealso prompted to specify and/or verify your information. Upon completion of the registration, a confir- mation screen like the one shown in Figure 7-6 is displayed. 168Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
Dim lngResult As LongDim strType As StringDim strFileName As StringDim strUsername As StringDim strPassword As StringDim strFaxNumber As String specify the user credentials and fax settingsstrUsername = Your User Name strPassword = Your Numeric Password strFaxnumber = Your Developer Fax Number strFileName = Path/FileName ex: c:testfax.pdf Read the file into a byte arrayfs = f.Open(strFileName, IO.FileMode.Open, IO.FileAccess.Read) Dim b(fs.Length - 1) As Bytefs.Read(b, 0, fs.Length) f = Nothingfs.Close() Retrieve the file type extensionstrType = Mid(strFileName, InStrRev(strFileName, . ) + 1) Call the Sendfax method to send the faxlngResult = wsFax.Sendfax(strUsername, strPassword, strFaxNumber, b, _ strType) See if submission to the fax queue was successfulIf lngResult > 0 ThenMsgBox( Your fax was submitted to the fax queue for transmission. ) ElseMsgBox( An error occurred in submitting the fax. ) End IfwsFax = NothingEnd Sub9.Input your specific username, password, fax number, and filename on the lines of code whereindicated. 10.Select File.Save All to save all changes to the project. 11.Select Debug.Start (or press F5) to run the project. Click the button to run the example. 12.You should see a message such as that shown in Figure 7-4 that indicates the success or failureof the fax submission. Figure 7-4167Other
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services
Figure 7-3At this point, let s get started writing the code. 1.Open Visual Studio .NET and select File.New.Project. 2.Select Visual Basic Project as the Project Type, and select Windows Application as the Template. For the project name, specify InterFaxSample, and for the path, specify the location where youwant the project to be created. Click OK to create the new project. 3.Drag and drop one command button from the Toolbox onto the form. 4.Add a reference to the InterFax API by selecting Project.Add Web Reference. For theURLfield, specify the location of the WSDLfile, such as http://ws.interfax.net/ dfs.asmx?wsdl. 5.Click the GO button so that Visual Studio locates the InterFax Web API. 6.Change the Web Reference Name to InterFaxso that you can use a shorter name in your project. 7.Click the Add Reference button to add the reference to your project. Visual Studio .NET uses theWSDLfile to identify the methods that are available for execution from your project. 8.Add the following procedure to Form1to the Clickevent of the button: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles Button1.ClickDim wsFax As New InterFax.InterFaxDim f As System.IO.FileDim fs As System.IO.FileStream166Chapter
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services