0

I am new with web service and .net. I would like to call a method from aspx.cs file, in my web service. How do i do that?

protected void SearchRec(object sender, EventArgs e)
    {
      ....
    }

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void example(string text_to_search)
    {
      .....//call SearchRec here
    }
John Saunders
  • 160,644
  • 26
  • 247
  • 397
ofer_e
  • 27
  • 1
  • 8

1 Answers1

1

If I understand you right, just write :

public void example(string text_to_search)
{
    this.SearchRec(text_to_search, null);
}

If they are both declared in the same class.

UPDATE: You have to transfer SearchRec logic and other similar methods to separate class. In your aspx.cs you can use it creating an instance of that class. And the same in webservice method. You can create an instance of that class and call it's methods.

Also, these topics can be usefull Difference between webservice, web methods & server side code? , http://msdn.microsoft.com/en-us/library/8wbhsy70(v=vs.90).aspx

Community
  • 1
  • 1
prvit
  • 956
  • 3
  • 9
  • 22