首先创建一个windows应用程序和web应用程序。
在web应用程序中,将网页切换到源代码并把源代码中一些没用的代码删掉,只保留头部,在windows应用程序读取网页源码时,这些都会被一起读下来,但这些都是没用的数据,而且删掉没什么影响。需要保留的代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
然后在Page_Load中实现功能,以下为一个将两个数相加并将和返回给winform的网页例子。
string A = Request.Form["a"].ToString();//由winform中传给网页的参数用a标识
string B = Request.Form["b"].ToString();
int C = Convert.ToInt32(A) + Convert.ToInt32(B);
Response.Write(C.ToString());//将数据写到网页中
在winform中实现传参的例子代码如下:
private void button1_Click(object sender, EventArgs e)
{
WebClient w = new WebClient();
System.Collections.Specialized.NameValueCollection VarPost = new Sys