Take the following steps to start a project and to add some code that will demonstrate how to consume LEADTOOLS WCF Services from a Silverlight application to load and display images. LEADTOOLS includes native Silverlight codecs for most formats so most image formats can be decoded and viewed natively within the Silverlight application without the WCF Service. In cases where your application needs to load a format for which LEADTOOLS does not provide a native Silverlight codec however, you can still use LEADTOOLS WCF Services to decode the image on the server and send the image back in a format which LEADTOOLS provides a native codec for.
Imports Load_And_Display.LEADTOOLSWCFImports System.ServiceModel
using Load_And_Display.LEADTOOLSWCF;using System.ServiceModel;
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)TryDim ofd As OpenFileDialog = New OpenFileDialog()If ofd.ShowDialog() = True ThenDim buffer As Byte() = NothingDim fileStream As FileStream = ofd.File.OpenRead()Trybuffer = New Byte(fileStream.Length - 1){}fileStream.Read(buffer, 0, CInt(fileStream.Length))FinallyfileStream.Dispose()End Try'Create RasterService and set optionsDim client As RasterServiceClient = New RasterServiceClient()Dim binding As BasicHttpBinding = New BasicHttpBinding()binding.MaxReceivedMessageSize = 50000000client.Endpoint.Binding = bindingAddHandler client.ConvertCompleted, AddressOf Of ConvertCompletedEventArgsDim source As RawBinaryData = New RawBinaryData()source.Data = buffer'Create RasterConvertOptions and set conversion optionsDim convertOptions As RasterConvertOptions = New RasterConvertOptions()convertOptions.Source = sourceconvertOptions.Destination = NothingconvertOptions.BitsPerPixel = 24convertOptions.Format = Load_And_Display.LEADTOOLSWCF.RasterImageFormat.PngconvertOptions.FirstPage = 1convertOptions.LastPage = 1Dim request As ConvertRequest = New ConvertRequest()request.ConvertOptions = convertOptions'Call serviceclient.ConvertAsync(request)End IfCatch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd Sub
private void Button_Click(object sender, RoutedEventArgs e){try{OpenFileDialog ofd = new OpenFileDialog();if (ofd.ShowDialog() == true){byte[] buffer = null;using (FileStream fileStream = ofd.File.OpenRead()){buffer = new byte[fileStream.Length];fileStream.Read(buffer, 0, (int)fileStream.Length);}//Create RasterService and set optionsRasterServiceClient client = new RasterServiceClient();BasicHttpBinding binding = new BasicHttpBinding();binding.MaxReceivedMessageSize = 50000000;client.Endpoint.Binding = binding;client.ConvertCompleted += new EventHandler<ConvertCompletedEventArgs>(client_ConvertCompleted);RawBinaryData source = new RawBinaryData();source.Data = buffer;//Create RasterConvertOptions and set conversion optionsRasterConvertOptions convertOptions = new RasterConvertOptions();convertOptions.Source = source;convertOptions.Destination = null;convertOptions.BitsPerPixel = 24;convertOptions.Format = Load_And_Display.LEADTOOLSWCF.RasterImageFormat.Png;convertOptions.FirstPage = 1;convertOptions.LastPage = 1;ConvertRequest request = new ConvertRequest();request.ConvertOptions = convertOptions;//Call serviceclient.ConvertAsync(request);}}catch (Exception ex){MessageBox.Show(ex.Message);}}
Private Sub client_ConvertCompleted(ByVal sender As Object, ByVal e As ConvertCompletedEventArgs)TryIf TypeOf e.Result Is ConvertResponse ThenDim convertResponse As ConvertResponse = CType(IIf(TypeOf e.Result Is ConvertResponse, e.Result, Nothing), ConvertResponse)'Image has been sent back from the service.'Load the image into the viewer.If TypeOf convertResponse.Destination Is RawBinaryData ThenDim ms As MemoryStream = New MemoryStream((CType(IIf(TypeOf convertResponse.Destination Is RawBinaryData, convertResponse.Destination, Nothing), RawBinaryData)).Data)TryDim codecs As RasterCodecs = New RasterCodecs()viewerControl.Image = codecs.Load(ms)Finallyms.Dispose()End TryEnd IfEnd IfCatch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd Sub
void client_ConvertCompleted(object sender, ConvertCompletedEventArgs e){try{if (e.Result is ConvertResponse){ConvertResponse convertResponse = e.Result as ConvertResponse;//Image has been sent back from the service.//Load the image into the viewer.if (convertResponse.Destination is RawBinaryData){using (MemoryStream ms = new MemoryStream((convertResponse.Destination as RawBinaryData).Data)){RasterCodecs codecs = new RasterCodecs();viewerControl.Image = codecs.Load(ms);}}}}catch (Exception ex){MessageBox.Show(ex.Message);}}
Build, and Run the program to test it.
Click the "Load" button, and select any image that LEADTOOLS supports.
Notes:
By default, the application will look for the service in the same address from which it was originally added. You can change this address using the RasterServiceClient.Endpoint.Address Property.
If you receive a cross domain exception, you may need to add clientaccesspolicy.xml to the root of your web domain. For more information, please visit https://msdn.microsoft.com/en-us/library/cc197955.aspx.
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
