【问题标题】:an object reference is required for nonstatic field or method. (web services)非静态字段或方法需要对象引用。 (网页服务)
【发布时间】:2011-04-11 05:27:16
【问题描述】:

我在使用网站应用程序的函数时遇到问题,该函数获取 xml 文件的 url 及其对应 xsd 文件的 url 并根据 xsd 验证 xml 文件。

虽然当我在我的 2 个文件上测试 web 方法时它可以工作,但在对我得到的按钮的功能进行编程时(非静态字段或方法需要对象引用。)

如果我尝试将验证方法设为静态,则它不会显示在我的网络应用程序中使用,并且在我测试网络服务时也不会显示。

如果我需要创建一个对象的实例,我不太确定如何正确地做到这一点。任何帮助表示赞赏,我无法从有关类似问题的问题中弄清楚。

受保护的 void Button2_Click(对象发送者,EventArgs e)
{
字符串 x = TextBox1.Text;
字符串 y = TextBox2.Text;
DevyoWebAapp.localhost.WebService.verification(x, y);
}

[WebMethod]  
public string verification(string x, string y)  
{  
    // Create the XmlSchemaSet class.  
    XmlSchemaSet sc = new XmlSchemaSet();  
    // Add the schema to the collection before performing validation  
    sc.Add(x, y);   
    // Define the validation settings.  
    XmlReaderSettings settings = new XmlReaderSettings();  
    settings.ValidationType = ValidationType.Schema;  
    settings.Schemas = sc; // Association
    settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
    // Create the XmlReader object.
    XmlReader reader = XmlReader.Create(x, settings);
    // Parse the file. 
    while (reader.Read()) ; // will call event handler if invalid
    return ("The XML file validation has completed");
}
// Display any validation errors.
private static void ValidationCallBack(object sender, ValidationEventArgs e)
{
    Console.WriteLine("Validation Error: {0}", e.Message);
}

}

【问题讨论】:

    标签: web-services web-applications object reference


    【解决方案1】:

    我认为它指的是服务,试试这样:

    protected void Button2_Click(object sender, EventArgs e)
    {
        string x = TextBox1.Text;
        string y = TextBox2.Text;
    
        var service = new DevyoWebAapp.localhost.WebService();
        service.verification(x, y);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多