2011-04-11 68 views
0

我在为网站应用程序使用函数时遇到问题,该网站应用程序会将xml文件的url及其相应的xsd文件的url并根据xsd验证xml文件。非静态字段或方法需要对象引用。 (网络服务)

虽然当我测试了我的2个文件的Web方法的工作,编程按钮我得到的功能时(对象引用需要非静态字段或方法)。

,如果我尝试做验证方法是静态的,那么它不会显示在我的Web应用程序中使用,并且当我测试Web服务时它不会显示。

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

保护无效Button2_Click(对象发件人,EventArgs的)
{
串x = TextBox1.Text;
string y = TextBox2.Text; DevyoWebAapp.localhost.WebService.verification(x,y);
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); 
} 

}

回答

0

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

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); 
} 
相关问题