usingSystem;
;
;
;
;
;
;
;
;
{
///<summary>
/// Summary description of GetBinaryFile.
///WebServices name: GetBinaryFile
///Function: Returns a binary byte array of a file object on the server.
///</summary>
[WebService(Namespace="/",
Description="Use the .NET framework in WebServices to pass binary files.")]
publicclassGetBinaryFile:
{
#regionComponentDesignergeneratedcode
//Required for Web Service Designer
privateIContainercomponents=null;
///<summary>
///Clean all resources in use.
///</summary>
protectedoverridevoidDispose(booldisposing)
{
if(disposing&&components!=null)
{
();
}
(disposing);
}
#endregion
publicclassImages:
{
///<summary>
/// Method provided by the web service, returning the byte array of the given file.
///</summary>
[WebMethod(Description="Method provided by the Web service, returning the byte array of the given file")]
publicbyte[]GetImage(stringrequestFileName)
{
///Get a picture on the server side
///If you test it yourself, please make sure to modify the actual physical path below
if(requestFileName==null||requestFileName=="")
returngetBinaryFile("D:\\");
else
returngetBinaryFile("D:\\"+requestFileName);
}
///<summary>
///getBinaryFile: Returns the byte array of given file path.
///</summary>
///<paramname="filename"></param>
///<returns></returns>
publicbyte[]getBinaryFile(stringfilename)
{
if((filename))
{
try
{
///Open existing file for reading.
FileStreams=(filename);
returnConvertStreamToByteBuffer(s);
}
catch(Exceptione)
{
returnnewbyte[0];
}
}
else
{
returnnewbyte[0];
}
}
///<summary>
///ConvertStreamToByteBuffer: Converts the given file stream into a binary byte array.
///</summary>
///<paramname="theStream"></param>
///<returns></returns>
publicbyte[]ConvertStreamToByteBuffer()
{
intb1;
=();
while((b1=())!=-1)
{
(((byte)b1));
}
();
}
[WebMethod(Description="Method provided by the Web service, returning the given file type.")]
publicstringGetImageType()
{
/// Here is just a test, you can dynamically output based on the actual file type
return"image/jpg";
}
}
}
}