我使用asp.net在webservice中收到错误 [英] iam getting error in webservice using asp.net

查看:89
本文介绍了我使用asp.net在webservice中收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分析器错误

描述:解析为此请求提供服务所需的资源时发生错误。请查看以下特定的解析错误详细信息并相应地修改源文件。

分析器错误消息:无法创建类型'JSONDemo.Service1'。

来源错误:


第1行:<%@ WebService 语言 = C# CodeBehind = Service1.asmx.cs < span class =code-attribute> = JSONDemo.Service1 %>

源文件:/Service1.asmx行:1

解决方案

使用下面的代码





 public string InsertWebservice(int CountryId,string UserName,int IsActive)
{
int rowsInserted;
using(SqlConnection conn = new SqlConnection(conStr))
{
string sql = string.Format(@INSERT INTO [TestDB]。[dbo]。[Table_1]([UserName] ,[CountryId],[IsActive])VALUES({0},'{1}',{2}),UserName,CountryId,IsActive);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
conn.Open();
rowsInserted = cmd.ExecuteNonQuery();
conn.Close();
cmd = null;
}
返回string.Format(谢谢,{0}插入的行数!,rowsInserted);
}


首先你需要在webservice中创建webmethod,如下所示



< pre lang =c#> [WebMethod]
public string Inserttblval( int CountryId, string UserName, int IsActive)
{
int rowsInserted;
SqlConnection conn = new SqlConnection(你的connectionstring);
string sql = string .Format( @ INSERT INTO [TestDB]。[dbo]。[Table_1]([UserName],[CountryId],[IsActive])VALUES({0},'{1 }',{2}),UserName,CountryId,IsActive);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
conn.Open();
rowsInserted = cmd.ExecuteNonQuery();
conn.Close();
cmd = null ;
return string .Format( 谢谢,{0}插入的行数!,rowsInserted);
}







下一页在aspx页面添加以下代码



 <   head     runat   = 服务器 >  
< title > < / title >
< script type = text / javascript src = http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js < span class =code-keyword>> < / script >
< script type = text / javascript src = http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js > < / script >
< script type = text / javascript >


(function(){

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not create type 'JSONDemo.Service1'.

Source Error:


Line 1:  <%@ WebService Language="C#" CodeBehind="Service1.asmx.cs" Class="JSONDemo.Service1" %>

Source File: /Service1.asmx    Line: 1

解决方案

use below code


public string InsertWebservice(int CountryId, string UserName, int IsActive)
    {
        int rowsInserted;
        using (SqlConnection conn = new SqlConnection(conStr))
       {
           string sql = string.Format(@"INSERT INTO [TestDB].[dbo].[Table_1] ([UserName],[CountryId],[IsActive]) VALUES ({0},'{1}',{2})", UserName, CountryId, IsActive);
           SqlCommand cmd = new SqlCommand();
           cmd.Connection = conn;
           cmd.CommandText = sql;
           cmd.CommandType = CommandType.Text;
           conn.Open();
           rowsInserted = cmd.ExecuteNonQuery();
           conn.Close();
           cmd = null;
       }
       return string.Format("Thank you, {0} number of rows inserted!", rowsInserted);
    }


first you need to create webmethod in webservice like below

[WebMethod]
public string Inserttblval(int CountryId, string UserName, int IsActive)
{
int rowsInserted;
SqlConnection conn = new SqlConnection(your connectionstring);
string sql = string.Format(@"INSERT INTO [TestDB].[dbo].[Table_1] ([UserName],[CountryId],[IsActive]) VALUES ({0},'{1}',{2})", UserName, CountryId, IsActive);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
conn.Open();
rowsInserted = cmd.ExecuteNonQuery();
conn.Close();
cmd = null;
return string.Format("Thank you, {0} number of rows inserted!", rowsInserted);
}




next in aspx page add below code

<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
    <script type="text/javascript">


(function () {


这篇关于我使用asp.net在webservice中收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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