我是C#和网络编程的新手。 Web服务错误的问题来自我调用它它给我这个错误System.InvalidOperationException:无法生成临时类(result = 1)... [英] am new At C# and web programing. problem in web service error come when i invoke it it is giving me this error System.InvalidOperationException: Unable to generate a temporary class (result=1)...

查看:96
本文介绍了我是C#和网络编程的新手。 Web服务错误的问题来自我调用它它给我这个错误System.InvalidOperationException:无法生成临时类(result = 1)...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.Services;

命名空间 RohitWebService
{
/// < 摘要 >
/// RohitService
的摘要说明
/// < / summary >
[WebService(Namespace = <跨度类= 代码串> http://Rohitshukla.org/)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem( false )]
// 要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class RohitService:System.Web.Services.WebService
{

[WebMethod]
public string HelloRohit()
{
return 代码由Rohit Shukla完成;
}

[WebMethod]
public 列表< String> []标记(字符串 sem)
{

List< String> [] data = semester.marks(sem);
返回数据;
}
}
}





使用System; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Data;
使用MySql.Data.MySqlClient;

名称空间RohitWebService
{
公共课学期
{



公共静态列表< 字符串 > [] marks(String mark1)
{
int i = 0;
//创建一个列表来存储结果
List < string < span class =code-keyword>> [] list = new List < string > [4];
list [0] = new List < string > ();
list [1] = new List < string > ();
list [2] = new List < string > ();
list [3] = new List < string > ();




字符串mysqlconnection =server = localhost ;; database = rohit_marks; uid = root; password = root;;

MySqlConnection connection = new MySqlConnection(mysqlconnection);

MySqlCommand cmd;
connection.Open();
try
{
//创建命令

cmd = connection.CreateCommand();
cmd.CommandText =select * from sem sem = @sem;;
cmd.Parameters.AddWithValue(@ sem,mark1);
cmd.ExecuteNonQuery();

//创建数据读取器并执行命令
MySqlDataReader dataReader = cmd.ExecuteReader();

//读取数据并将它们存储在列表中
while(dataReader.Read())
{
list [0] .Add(dataReader [ subject] +);
list [1] .Add(dataReader [sem] +);
list [2] .Add(dataReader [mark_obtained] +);

}

//关闭数据读取器
dataReader.Close();
}
catch(MySqlException)
{
throw;
}

最后
{
if(connection.State == ConnectionState.Open)
{
connection.Close();
}
}
返回列表;

}
}
}

解决方案

这只是语法错误。你不能说我不知道。在尝试部署之前始终完全编译所有项目,编译器会告诉您错误的位置。



-SA

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace RohitWebService
{
    /// <summary>
    /// Summary description for RohitService
    /// </summary>
    [WebService(Namespace = "http://Rohitshukla.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class RohitService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloRohit()
        {
            return "code is done by Rohit Shukla";
        }

        [WebMethod]
        public List<String>[] Marks(string sem)
        {

            List<String>[] data =  semester.marks(sem);
            return data;
        }
    }
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

namespace RohitWebService
{
    public class semester
    {



        public static List<String>[] marks(String mark1)
        {
            int i = 0;
            //Create a list to store the result
            List<string>[] list = new List<string>[4];
            list[0] = new List<string>();
            list[1] = new List<string>();
            list[2] = new List<string>();
            list[3] = new List<string>();




            String mysqlconnection = "server=localhost;;database=rohit_marks;uid=root;password=root;";

            MySqlConnection connection = new MySqlConnection(mysqlconnection);

            MySqlCommand cmd;
            connection.Open();
            try
            {
                //Create Command

                cmd = connection.CreateCommand();
                cmd.CommandText = "select * from marks where sem = @sem ;";
                cmd.Parameters.AddWithValue("@sem", mark1);
                cmd.ExecuteNonQuery();

                //Create a data reader and Execute the command
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    list[0].Add(dataReader["subject"] + "");
                    list[1].Add(dataReader["sem"] + "");
                    list[2].Add(dataReader["mark_obtained"] + "");

                }

                //close Data Reader
                dataReader.Close();
            }
            catch (MySqlException)
            {
                throw;
            }

            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return list;

        }
    }
}

解决方案

This is just the syntax error. You cannot say "I don't know". Always fully compile all your project before trying to deploy it, and the compiler will tell you where the error is.

—SA


这篇关于我是C#和网络编程的新手。 Web服务错误的问题来自我调用它它给我这个错误System.InvalidOperationException:无法生成临时类(result = 1)...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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