开发者

Creating a 3D visual in memory using WPF in a Web Application. Works in Cassini, doesn't in IIS

Bit of a weird title, but here's the deal. For a web site I'm working on, we have the need to开发者_JAVA百科 generate quasi-3D images on the fly. Basically, it's for an art site, and we have the need to show a 3D representation of a Canvas given a 2D image (jpg). (See here for some context.) The approach we're taking is to leverage the WPF 3D API and create a Viewport3D in code, add a bunch of points to it with the correct dimensions, and then apply the textures from the original jpg appropriately.

While testing it, I was testing it the whole time in a sandbox environment, and in the built in Cassini web server in Visual Studio. While trying to migrate it over to the actual code repository and testing it there, it stopped working. The image that's pumped out is the correct size, but is completely blank. It's totally black. After hours of banging my head against the wall, I figured out that it's an IIS issue.

I created a simple sample app to demonstrate the issue (doesn't add images though it just paints all sides green), however since most of the code is largely irrelevant to the question, I won't put it here, rather I'll post a link to it:

http://www.box.net/shared/55bznpfns1

If you do download it and want to run it, in the code behind of Default.aspx you'll see this:

    protected void buttonClick(object sender, EventArgs e)
    {
        var path = @"C:\test\output\output.png";
        IISvsCassini.WpfImageCreator.CreateWPFImage(path);
    }

Feel free to change that path to whatever, and make sure that the correct permissions are in place as it'll try to save a file there.

If you try that sample in Visual Studio with Cassini, it'll work fine, and you should have a new file called "output.png" which has a green 3D cube. If you try it in IIS, you'll get a blank image.

A few points: Before anyone asks, yes, I gave all the proper folders the correct permission issues. I also do the actual 3D generation and image saving on a separate thread with the Apartment state set to STA.

I know this is a bit of an unusual case of fusing WPF and ASP.Net, but by some chance, does anyone have any ideas? Is there some setting in IIS that I need to change? Is there some limitation to the WPF API that won't allow it to run out of IIS?


If you are running on 2008 Server that has been installed as Core Server (no UI) the WPF bits + drivers that DUCE and MILCORE need to render things are not there for RenderTargetBitmap() and other things. MS does this to reduce the attack surface on the server and reliability.

Unfortunately you cannot upgrade from Core Server to Full you must reinstall the OS - https://serverfault.com/questions/4945/install-gui-on-windows-server-2008-core


Well this sucks:

https://connect.microsoft.com/VisualStudio/feedback/details/361469/net-3-5-sp1-breaks-use-of-wpf-under-iis

Turns out it's not supported. It seems like it was at one point, but no longer works. Real shame.... It also doesn't work from within a Windows Service, but it DOES work in Cassini, and it DOES work in a Console Application. Oh well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜