17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5: <strong>FILESTREAM</strong> with ASP.NET and Silverlight}if (ms != null && ms.Length > 0){context.Response.AddHeader("content-length",ms.Length.ToString());// Reset the current position in the MemoryStreamms.Position = 0;// .NET 4.0 and later method onlyms.CopyTo(context.Response.OutputStream);}Listing 5-20:Updated ProcessRequest() method using a WCF call to obtain the <strong>FILESTREAM</strong> data.Because the interface definition <strong>of</strong> IItemData matches that <strong>of</strong> the ItemData class weused to call, there is no difference in the code beyond the creation <strong>of</strong> the channel. Inessence, we have replaced the call to the constructor <strong>of</strong> the ItemData class with a WCFcall over TCP.Be sure to make the URI <strong>of</strong> the EndpointAddress in this code match up with theURI created in the console application. If you will be running this code actually acrossdifferent machines, replace localhost with the name or IP address <strong>of</strong> the computerrunning the WCF service. To avoid hard-coding the name or IP address <strong>of</strong> the server,the WCF client configuration can also be created in the web.config file, but that is notdemonstrated here.Testing the application from Visual StudioTo test this code from Visual Studio, first right-click the ConsoleHost project andselect Debug, Start new instance. This will start the console application and, with it,the WCF service. Next, right-click the web application and start a new instance <strong>of</strong> it, alsoin debug mode.215

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!