Sales
Click for numbers
Welcome User Tools Developer Tools Prices Help Sign up Login
You are here: Home > Developer Tools > Fax Web Service > Samples > Java - How to fax two files at once

Fax Web Service Code Sample

Java - How to fax two files

Download the Java project files.

class TestFax { public static void main(String[] args) throws Exception {
String str1 = "First test fax.";
String str2 = "Second test fax.";

//Concat the Strings in order to use the Web Service
String testStr = str1.concat(str2);

Integer len1 = new Integer(str1.length());
Integer len2 = new Integer(str2.length());
int testStrLen = testStr.length();

String fileLen = len1.toString().concat(";").concat(len2.toString());

byte[] b = new byte[testStrLen];
for (int i=0;i<testStrLen;i++) {
char c = testStr.charAt(i); b[i] = (byte)c;
}
// Create date object
GregorianCalendar gc = new GregorianCalendar(2003,3,15,17,10);
// 15 - March - 2003, 17:10
try {
long result; // Create an instance of the Web Service Object
InterFaxSoapStub ifs = new InterFaxSoapStub(new URL("http://ws.interfax.net/DFS.asmx"), new Service(new QName("Sendfax")));
System.out.println("Begin to send fax");
// Invoke SendfaxEx_2 method
result = ifs.SendfaxEx_2("MyUserName","MyPassword","+1-212-4567890", "", b, "TXT;TXT", fileLen, gc, 0, "CSID", "", "", "Java Test", "dummy@interfax.net", "A4", "Portrait", true, false);

if (result > 0)
// Positive result indicates that the fax was sent successfully.
// The return value is the TransactionID.
System.out.println("Fax was sent successfully. Transaction number: " + result);
else
//Fax sending failure.
System.out.println("Error sending fax!" + result);
}
catch(Exception e) {
System.out.println(e.toString());
} } }



About | Contact | Privacy | Terms | Partners | Login | System Status

© Interfax Inc