HowTo make File Transfer (FT) call? ( .NET sample )
The attached program is a console application that allows the user to make a FT uploadFile call in the Sandbox environment. Response details (success or failure) are displayed on the console. The application has been written in C# using the Visual Studio 2005 environment.
The application expects the parameters required for the uploadFile call (BDX jobID, BDX fileRefID, name of file to upload, user's sandbox token) to be present in the app.config file.
Pre-requisites: A Bulk Data Exchange(BDX) job has been created using the BDX createUploadJob call.
Notes: The jobID and fileReferenceId returned by the BDX call are required to be supplied to the UploadFile call.
Consuming File Transfer Web Service
Visual Studio .NET 2005 provides the capability to create class files that contain the proxy code to access the web services. The generated class is used to instantiate objects for communicating with the Web services.
1. Use the ServiceModel Metadata Utility Tool (svcutil.exe) to generate a configuration file and a code library to interface to our service. Two files will be generated - FileTransferService.cs and app.config. The utility can be found at the Windows SDK installation location, specifically, C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin
svcutil.exe https://storage.sandbox.ebay.com/FileTransferService?wsdl /config:app.config
2. Open Visual Studio 2005 and create a new solution that is a C# console application. Add the files generated in the step above to the project.
3. Edit the app.config file to contain
<add key="jobID" value="BDX JobID"></add>
<add key="fileRefID" value="BDX FileRefID"></add>
<add key="fileName" value="C:\\AddFPItem.gz"></add>
<add key="SandboxToken" value="YourSandboxToken"></add>
3. Make sure that the endpoint address in the app.config file is https://storage.sandbox.ebay.com/FileTransferService. Also ensure that the tag underneath the custom binding definition is <httpsTransport> instead of <httpTransport> .
4. Comment out the anyField field and the associated property in the BaseServiceResponse class in the FileTransferService.cs file.
5. Add a reference to System.ServiceModel and System.ServiceModel.Channels
6. The project is now ready for making the FT calls available.
Below is a code snippet that shows how to make a call to the uploadFile function. Download the sample application for details about the code.
FileTransferServicePortClient client = new FileTransferServicePortClient("FileTransferServiceSOAP");
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
HttpRequestMessageProperty httpRequest = new HttpRequestMessageProperty();
//Add the request headers
//Create upload file request
UploadFileRequest uploadReq = new UploadFileRequest();
uploadReq.fileAttachment = new FileAttachment();
FileStream fs = File.OpenRead(fileName);
uploadReq.fileReferenceId = fileRefId;
uploadReq.taskReferenceId = jobID;
uploadReq.fileFormat = "gzip";
//Make the uploadFile call and return the response
UploadFileResponse uploadResponse = client.uploadFile(uploadReq);
// Examine the response to determine success/failure