Listing 1: SoapExceptionDetail

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="unqualified">

	<!-- used in soap exception handling to define detail node -->

	<!-- global definitions -->
	<xs:element name="ClientErrorMessage" type="xs:string"/>
	<xs:element name="ServerErrorMessage" type="xs:string"/>
	<xs:element name="StackTrace" type="xs:string"/>
	<!-- Error element -->
	<xs:element name="Error">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="ClientErrorMessage"/>
				<xs:element ref="ServerErrorMessage"/>
				<xs:element ref="StackTrace"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>

Lisiting 2: Soap Error Message

<env:Envelope  xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <env:Header>
 </env:Header>
 <env:Body>
  <env:Fault    xmlns:fault="http://schemas.xmlsoap.org/soap/envelope/">
   <faultcode>fault:Client</faultcode>
   <faultstring>This is a custom soap exception</faultstring>
   <faultactor>Client</faultactor>
   <detail>
    <Error>
     <ClientErrorMessage>This is a client error message.</ClientErrorMessage>
     <ServerErrorMessage>This would be a server error message if the fault type was
	  'server'.</ServerErrorMessage>
     <StackTrace>This is a stack trace.</StackTrace>
    </Error>
   </detail>
  </env:Fault>
 </env:Body>
</env:Envelope>

Listing 3

// build and throw a client SOAP exception
    QName faultCode = new QName("http://schemas.xmlSOAP.org/SOAP/envelope/", "Client");
    String faultString = "This is a custom SOAP exception";
    // set fault type to client to indicate the client operation caused this exception
	String faultActor = "Client";
    throw SOAPUtil.buildSoapFaultException(faultCode, faultString, faultActor,
	"This is a client error message generated from the throwClientSoapException method in
	 WebLogic.", "This would be a server error message if the fault type was 'server'.",
	  "This is a stack trace.");

Listing 4

// define the detail element
    Detail detail = weblogic.webservice.util.FaultUtil.newDetail();

    try {
      // define the xml structure for the detail element
      Name name = SOAPFactory.newInstance().createName("Error", "", SOAP_NAMESPACE);
      DetailEntry entry = detail.addDetailEntry(name);
      // add the values to the detail element
	   entry.addChildElement("ClientErrorMessage").addTextNode(clientErrorMessage);
      entry.addChildElement("ServerErrorMessage").addTextNode(serverErrorMessage);
      entry.addChildElement("StackTrace").addTextNode(stackTrace);
    }
    catch (Exception ex) {
      Logger.getLogger("GenerateSoapException.class").warning("An exception occurred in
	   buildSoapFaultException of SOAPUtil. Exception message is: " + ex.getMessage());
      throw new RuntimeException(ex);
    }

    // return the SoapFaultException
    return new SoapFaultException(faultCode, faultString, faultActor, detail);

Listing 5: ASP.NET client SoapException code

private void bnSoapError_Click(object sender, System.EventArgs e)
{
weblogic.BusinessDelegate proxy = new weblogic.BusinessDelegate();
try
	{
	proxy.throwClientSoapException();
	}
catch (SoapException ex)
	{

	string message = "";
	//Create a DataSet instance
	DataSet dsError = new DataSet();

	//Create a DataView instance;
	DataView dataView = new DataView();

	//Get SoapExceptionDetail.xsd full path
	string schemaRelativePath = "../schemas/SoapExceptionDetail.xsd";
	string schemaFullPath = HttpContext.Current.Server.MapPath(schemaRelativePath);

	//Get exception detail xml string
	string xmlString = ex.Detail.OuterXml;

	//Read the xml string into a StringReader object
	StringReader stringReader = new StringReader(xmlString);

	//Read the StringReader into the XmlReader object
	XmlReader xmlReader = new XmlTextReader(stringReader);

	//Read the Schema into the DataSet
	dsError.ReadXmlSchema(schemaFullPath);
	//Read the Xml into the DataSet
	dsError.ReadXml(xmlReader, XmlReadMode.IgnoreSchema);

	// Create an instance of  DataView object
	dataView = new DataView();

	// Specify the table
	dataView.Table = dsError.Tables["Error"];
	// Get the first row
	DataRow dsErrorRow = dataView.Table.Rows[0];

	// Get the relevant Error message
	message = dsErrorRow["ClientErrorMessage"].ToString();

	txtSoapClientMessage.Text = message;

}

}

Listing 6: ASP.NET code to perform a binary transfer

// check the extention of the file
if(!this.CheckFileExtensionIsValid(fileInput.Value))
{
	lblError.Text = "Only files with a .jpg, .jpeg and .gif extention may be uploaded.";
	return;
}

// Ceate the temporary path
	// DIRECTORY C:\TEMP MUST EXIST
	string imageFileName = System.IO.Path.GetFileName(fileInput.Value);
	string tempImagePath = "c:\\temp\\" + imageFileName;

	//Save it to the server as a temporary file before processing
	fileInput.PostedFile.SaveAs(tempImagePath);

	//Get the maximum image file size in bytes
	int maxImageSize = 2097152;

	//Do not allow images larger than the maximum size
	if(fileInput.PostedFile.ContentLength > maxImageSize )
	{
		lblError.Text = "Can not upload a file larger than " + maxImageSize + " bytes";
		return;
	}

		
	//Get file and convert it to an array of bytes
	System.Drawing.Image image = System.Drawing.Image.FromFile(tempImagePath);
	MemoryStream memoryStream = new MemoryStream();

	switch(fileExtention)
	{
		case "gif":
		{
			image.Save(memoryStream, ImageFormat.Gif);
			break;
		}
		case "jpg":
		case "jpeg":
		{
			image.Save(memoryStream, ImageFormat.Jpeg);
			break;
		}
	}

	long  length = memoryStream.Length;
	byte[] byteArray = new byte[length];
	byteArray = memoryStream.ToArray();

	// Discard Image
	if(image != null)
	{
		image.Dispose();
	}

	//Flush Memmory Stream
	if(memoryStream != null)
	{
		memoryStream.Flush();
	}

	// Delete the temp file
	File.Delete(tempImagePath);

	// send via web service to save
	weblogic.BusinessDelegate proxy = new weblogic.BusinessDelegate();
	bool successFlag = proxy.saveBinaryData(imageFileName, byteArray);
	if (successFlag)
	{
		lblError.Text = "The file was successfully uploaded.";
	}
	else
	{
		lblError.Text = "The file was NOT successfully uploaded.";
	}
}

Listing 7: WebLogic code for binary upload

public static boolean saveBinaryData(String fileName, byte[] fileData) {

    Logger.getLogger("UploadImages.class").info("Entering saveBinaryData method. fileName =
	 " + fileName);

    boolean bResult = false;

    // for this example, we will store all images in the same directory
	// in a production environment, you may which to use subdirectories based on client id
	// or a similar id

    // check that the directory exists, if not create it
    try {

      File attachmentDir = new File(imageDirectory);
      if (!attachmentDir.exists()) {
        // create directory
        boolean bDirCreated = attachmentDir.mkdirs();
        if (!bDirCreated) {
          throw new IOException("Unable to create directory: " +
		   attachmentDir.getAbsolutePath());
        }
      }

      // save the binary data to a file on the file system
      String fullFileName = imageDirectory + "\\" + fileName;
      File attachmentFile = new File(fullFileName);
      FileOutputStream fileStream = null;
      fileStream = new FileOutputStream(attachmentFile);
      fileStream.write(fileData);
      // close filestream
      fileStream.close();
      bResult = true;
    }
    catch (IOException ex) {
      Logger.getLogger("UploadImages.class").warning("An IOException occured in
	   saveBinaryData. The message is: " + ex.getMessage());
      throw new RuntimeException(ex);
    }
    return bResult;

  }

Listing 8: WebLogic code to return binary image data

public static byte[] getBinaryData(String fileName) {

    Logger.getLogger("ViewImages.class").info("Entering viewAppraisalAttachment method.
	 fileName = " + fileName);

    String imageDirectory = UploadImages.imageDirectory;

    // retrieve the file
    String fullFileName = imageDirectory + "\\" + fileName;
    File imageFile = new File(fullFileName);
    FileInputStream fileStream = null;
    try {
      fileStream = new FileInputStream(imageFile);
    }
    catch (FileNotFoundException ex) {
      Logger.getLogger("ViewImages.class").info("FileNotFoundException occured. fileName =
	   " + fileName + ". Message is: " + ex.getMessage());
      throw new RuntimeException(ex);
    }

    int fileLength = (int) imageFile.length();
    byte[] fileData = new byte[fileLength];
    try {
      fileStream.read(fileData);
      // close filestream
      fileStream.close();
    }
    catch (IOException ex) {
      Logger.getLogger("ViewImages.class").info("IOException in viewAppraisalAttachment
	   occured. fullFileName = " + fullFileName + ". Message is: " + ex.getMessage());
      throw new RuntimeException(ex);
    }

    return fileData;

  }

Listing 9: ASP.NET client code to display binary data as an image within Intenet Explorer

private void Page_Load(object sender, System.EventArgs e)
{

	object objFileName = Request.QueryString["FileName"];
	if (!(objFileName == null || objFileName.ToString() == ""))
	{
		string fileName = objFileName.ToString();
		string fileExtension = fileName.Substring(fileName.IndexOf(".")+ 1).ToLower();

		// call web service to obtain image array of bytes
		weblogic.BusinessDelegate proxy = new weblogic.BusinessDelegate();
		byte[] byteArray = proxy.getBinaryData(fileName);

		switch (fileExtension)
		{
			case "jpeg":
			case "jpg":
			{
				Response.ContentType = "image/JPEG";
				break;
			}
			case "gif":
			{
				Response.ContentType = "image/gif";
				break;
			}
		}
			
		Response.BinaryWrite(byteArray);
		}
	else
	{
		Response.Write("Please specify a valid filename in the query string");
	}
}


Listing 10
// get page configuration
string currentPage = HttpContext.Current.Session["CurrentPage"].ToString();
Hashtable hashPageConfig = (Hashtable) HttpContext.Current.Application["PageConfig"];
PageConfiguration pageConfiguration = (PageConfiguration) hashPageConfig[currentPage];

// redirect forward if not on the first page
if (pageConfiguration.NextPageName != "")
{
string urlNext = NavigationController.getPageURL(pageConfiguration.NextPageName);
HttpContext.Current.Session["CurrentPage"] = pageConfiguration.NextPageName;
	HttpContext.Current.Response.Redirect(urlNext);
}

Additional Code....zip file