问题更正为:我在网站中使用FORMS(WEB.config)验证以前,我的WEBSERVICE完全正常,可使用了
FORMS验证以后出错:谢谢指教

解决方案 »

  1.   

    这个问题是由于WebService返回信息造成的,因为调用web service方法期待返回的格式是xml,而你的web service这是返回一个带有错误信息的html格式。解决问题的方法有两种:
    1、在web service方法中通过try-catch抛出一个异常。
    2、直接在调用方使用try-catch捕获异常,然后对异常做处理。
      

  2.   

    在webservice独立的目录那里重新写一个WEB.config。试试看
      

  3.   

    WEB Service文件如下:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Web;
    using System.Web.Services;
    using System.Data.SqlClient;
    namespace Service
    {
    /// <summary>
    /// dbQuitGame 的摘要说明。
    /// </summary>
    [WebService(Namespace="http://www.qgzxol.com")]
    public class dbQuitGame : System.Web.Services.WebService
    {
    public dbQuitGame()
    {
    //CODEGEN:该调用是 ASP.NET Web 服务设计器所必需的
    InitializeComponent();
    connStr =System.Configuration.ConfigurationSettings.AppSettings["connStr"];
    //connStr ="data source=QUITGAME;initial catalog=E-business;user id=sa;pwd=sa;packet size=4096";
    }
    private String  connStr;
    #region Component Designer generated code

    //Web 服务设计器所必需的
    private IContainer components = null;

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    { } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if(disposing && components != null)
    {
    components.Dispose();
    }
    base.Dispose(disposing);
    }

    #endregion // WEB 服务示例
    // HelloWorld() 示例服务返回字符串 Hello World
    // 若要生成,请取消注释下列行,然后保存并生成项目
    // 若要测试此 Web 服务,请按 F5 键 [WebMethod] public DataSet Populate(String SQL)
    {
    SqlConnection myConn = new SqlConnection(connStr);
    SqlDataAdapter myCmd = new SqlDataAdapter(SQL,myConn);
    DataSet ds = new DataSet();
    myCmd.Fill(ds,"dsTable");
    return ds;
    }
    [WebMethod]
    public String RunSQL(String SQL)
    {
    try 
    {
    SqlConnection myConn = new System.Data.SqlClient.SqlConnection(connStr);
    SqlCommand myCmd = new System.Data.SqlClient.SqlCommand(SQL,myConn);
    myConn.Open();
    myCmd.ExecuteNonQuery();
    myConn.Close();
    return("OK");
    }
    catch(Exception e)
    {
    String ret = "Exception:"+e.ToString();
    return ret;
    } }
    }
    }
    在用 FORMS验证:
    private void Ok_btn_Click(object sender, System.EventArgs e)
    {
    if(FormsAuthentication.Authenticate(userName.Text,userPwd.Text))
    {
    FormsAuthentication.RedirectFromLoginPage(userName.Text,false);
    }
    else
    msg.Text = "ERR,Wrong UserName,Password!Input Admin/aspx or QuitGame/QuitGame";
    }之前,没有任何问题,可以调用之进行 RunSQL()操作,但是在用了上面那个验证之后,没有调用 WEB Service 的操作均正常,但只要调用了WEB Service之后,进行RunSQL()操作的时候 就会有上 面的错误。请帮帮忙啊。
      

  4.   

    首先确认你有访问Web service的权限。检查你是否在Web service中也实行了Form验证,其中设置了loginUrl的属性?
    你用下面的方法,可以判定你的问题所在:
    假设你调用的方法是WebService的MyMethod,你的web service代理是MyWebService, 在你的调用代码中:try
    {
         MyWebService myService=new MyWebService();
         myService.MyMethod();
    }
    catch(Exception ex)
    {
          Response.Write(ex.Message)
    }
      

  5.   

    有了新的进展, niwalker()按照您的写法,ex.toString()的信息如下
    System.Net.WebException: 请求失败,错误信息为: -- 
    Object moved to here.
    --. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at Admin.localhost.dbQuitGame.RunSQL(String SQL) in G:\Docus\myweb\E_BUSINESS\Admin\Web 引用\localhost\Reference.cs:line 57 at Admin.addGoods.Add_btn_Click(Object sender, EventArgs e) in g:\docus\myweb\e_business\admin\addgoods.aspx.cs:line 85 
    直接输入 WEBService 路径,要求登陆,成功转到WEBService 路径,测试RunSQL方法,正常,这时候 再去调用WEBService 的地方,操作依然返回同样的出错信息。我的WEBService 和 WEB文件在同一工程,同一路径中
      

  6.   

    最好不要让你的WEBService处于需要验证的目录可以试试在login.aspx的page_load里判断
    FormsAuthentication.GetRedirectUrl("*",false)为WEBService的时候
    直接通过验证
      

  7.   

    那怎么保证 WEBService 不被非法调用啊?