这是我的网络服务代码:无法从Web服务返回我的SQL连接对象asp.net项目
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.Sql;
using System.Data.SqlClient;
namespace DBwebService
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://kse.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 WebService1 : System.Web.Services.WebService
{
string ConnectionString = "Data Source=Shumaila-PC;Initial Catalog=kse;Persist Security Info=True;User ID=sa;Password=sa";
public SqlConnection Conn;
[WebMethod]
public void SqlConn()
{
Conn = new SqlConnection(ConnectionString);
// Conn.Open();
}
//catch (SqlException ex)
//{
// //Console.WriteLine("Connection Unsuccessful " + ex.Message);
//}
}
}
我需要回到我的SQL连接对象,这样我可以在我的asp.net叫它pid roject。但是当我做了
public SqlConnection SqlConn()
和
return.Conn();
这给了我下面的错误
Server Error in '/' Application. 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 'DBwebService.WebService1'.
Source Error:
Line 1: <%@ WebService Language="C#" CodeBehind="WebService1.asmx.cs" Class="DBwebService.WebService1" %>
Source File: /WebService1.asmx Line: 1
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 --. Metadata contains a reference that cannot be resolved: 'http://localhost:50387/WebService1.asmx'. The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: ' Server Error in '/' Application. Parser Error '. The remote server returned an error: (500) Internal Server Error. If the service is defined in the current solution, try building the solution and adding the service reference again.
只返回康恩,不康恩() – mslliviu
这是错字。我已经编码康涅狄格州 –