如何创建在Web应用程序中使用的窗口应用程序DLL [英] how to create window application dll to be used in web application

查看:108
本文介绍了如何创建在Web应用程序中使用的窗口应用程序DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的WindowsClassLibrary代码:



 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
使用 System.Net;
使用 System.IO;
使用 System.Drawing.Drawing2D;
使用 System.Drawing.Design;
使用 System.Threading;
使用 System.Drawing.Imaging;
使用 System.Configuration;
使用 System.Xml;
使用 InfoSoftGlobal;

命名空间 GraphCapture
{
public partial class Form1:UserControl
{
public Form1()
{
InitializeComponent();
}
public string filePath;
受保护 void SwfToImage()
{


屏幕= Screen.PrimaryScreen;


Rectangle bounds = new Rectangle(axShockwaveFlash1.Location,axShockwaveFlash1.Size);
使用(位图位图= 位图(bounds.Width,bounds.Height))
{
使用(图形g = Graphics.FromImage(位图))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic ;
g.CopyFromScreen( new Point(bounds.Left,bounds.Top),Point.Empty,bounds.Size);
}

bitmap.Save(filePath + / FCF_Column3D.Jpeg,ImageFormat.Jpeg);
}

}

public void GetGraph(XmlDocument strXml, string fPath)
{
string appPath = file:/// + Application.StartupPath + \\FusionCharts\\FCF_Column3D.swf;
appPath = appPath.Replace( \\ /);
filePath = fPath;
FileStream fs = new FileStream(filePath + \\ FCF_Column3D.Xml,FileMode.Open,FileAccess.Read);
strXml.Load(fs);
// string strChart = filePath + @?dataXML =+ strXml.InnerXml.Replace(\\ \\,')+®isterwithjs= 1;
// string ChartXML = appPath + strChart;
string ChartXML = appPath + @ ?dataXML = + strXml.InnerXml.Replace( \ ')。替换( )+ @isterwithjs = 1;



string XML = ChartXML;

axShockwaveFlash1.Movie = XML;
timer1.Start();


}

private void Form1_Load( object sender,EventArgs e)
{


}


private void timer1_Tick( object sender,EventArgs e)
{
SwfToImage();
timer1.Stop();

}
}
}





这里我收到错误 d27cdb6e-ae6d-11cf-96b8-444553540000'无法实例化,因为从Web应用程序调用dll时,当前线程不在单线程单元中

解决方案

Windows dll不适合在Web应用程序中使用。只需将代码放在您网站的一个类中,并在进行相关修改后从那里调用它。另请注意,这不会从客户端读取任何内容或将任何内容保存到客户端,文件必须在已经上载后存在于服务器上,并且生成的图像也将保存在服务器上。

您无法在Web环境中使用Windows窗体:它们完全不同。首先,C#代码是基于服务器的 - 这意味着它总是在服务器上执行,而不是在客户端上执行。因此,即使你可以让它运行(你不能这样做。未设置IIS),Web主机管理员可以看到所显示的内容,而不是半个世界之外的客户端。



你不能只找到一些代码,并假设它可以在所有环境下工作,不仅仅是你可以找到一辆车,并假设它可以作为潜艇使用!



查看代码,弄清楚它是如何工作的,并将逻辑提取到基于Web的解决方案中。


Here is my code for WindowsClassLibrary:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Threading;
using System.Drawing.Imaging;
using System.Configuration;
using System.Xml;
using InfoSoftGlobal;

namespace GraphCapture
{
    public partial class Form1 : UserControl 
    {
        public Form1()
        {
            InitializeComponent();
        }
        public string filePath ;
        protected void SwfToImage()
        {
          

            Screen screen = Screen.PrimaryScreen;
           
         
            Rectangle bounds = new Rectangle(axShockwaveFlash1.Location, axShockwaveFlash1.Size);
            using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
            {
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
                }

                bitmap.Save(filePath + "/FCF_Column3D.Jpeg", ImageFormat.Jpeg);
            }

        }

        public void GetGraph(XmlDocument strXml,string fPath)
        {
            string appPath = "file:///" + Application.StartupPath + "\\FusionCharts\\FCF_Column3D.swf";
            appPath = appPath.Replace("\\", "/");
            filePath = fPath;
            FileStream fs = new FileStream(filePath + "\\FCF_Column3D.Xml", FileMode.Open, FileAccess.Read);
            strXml.Load(fs);
            //string strChart = filePath + @"?dataXML=" + strXml.InnerXml.Replace("\"","'")  + "®isterwithjs=1";
            //string ChartXML = appPath + strChart;
            string ChartXML = appPath + @"?dataXML=" + strXml.InnerXml.Replace("\"", "'").Replace("#", "") + "®isterwithjs=1";


        
            string XML = ChartXML;

            axShockwaveFlash1.Movie = XML;
            timer1.Start(); 


        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
          

        }

       
        private void timer1_Tick(object sender, EventArgs e)
        {
            SwfToImage();
            timer1.Stop();
           
        }
    }
}



Here I am getting error d27cdb6e-ae6d-11cf-96b8-444553540000' cannot be instantiated because the current thread is not in a single-threaded apartment
while calling dll from web application.

解决方案

Windows dlls are not suitable for use in a web app. Just put the code in a class in your website and call it from there after making the relevant amendments. Also note that this isn't going to read anything from the client or save anything to the client, the file will have to exist on the server after being already uploaded, and the resulting image will be saved on the server also.


You cannot use Windows forms in a web environment: they are totally different. For one thing, C# code is Server based - which means it always executes on the Server, not the Client. So even if you could get it to run (which you can't. IIS isn't set up for that) whatever was displayed would be visible to the Web host admin, and not to the client half a world away.

You cannot just find some code and assume it will work under all environments, any more than you can find a car, and assume it will work as a submarine!

Look at the code, work out how it works, and extract the logic into a web-based solution.


这篇关于如何创建在Web应用程序中使用的窗口应用程序DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆