views:

22

answers:

3

Hi,

Its possible expose many class in single asmx in Web Service C#, this for generate one Proxy class, and consume proxy from client like: Proxy.UserService.User and Proxy.ImageService.GetImage I try this but dont Work.

namespace ServiciosWeb
{
   [WebService(Namespace = "http://tempuri.org/")]
   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   [System.ComponentModel.ToolboxItem(false)]
   public class Services : System.Web.Services.WebService
   {
   }

   public class ImageService : Services.IService
   {
      [WebMethod]
      public string GetImage()
      {
        return "Image";
      }
   }

  public class UserService : Services.IService
  {
    [WebMethod]
    public string User()
    {
        return "User";
    }
  }
}
+2  A: 

A classic ASMX web service is a class that needs to derive from System.Web.Services.WebService and decorated with the [WebService] attribute. If you want to expose multiple services you might need to have multiple ASMX files. Another possibility is to simply put the two web methods inside the existing service class so that when you generate the proxy class on the client they will be visible.

Darin Dimitrov
+2  A: 

no that is not possible with [WebService] and [WebMethod]s.

Taras B
+1  A: 

You can not bind multiple classes to a single asmx, what you could do however -if you want to offer a multitude of class-files- is use the same class name like partial class. Would need to check to see if each class needs to be derived from IService, but I've did this in a project and it worked.

namespace ServiciosWeb 
    { 
       [WebService(Namespace = "http://tempuri.org/")] 
       [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
       [System.ComponentModel.ToolboxItem(false)] 
       public partial class Services : System.Web.Services.WebService 
       { 
       } 


   public partial class Services : Services.IService 
   { 
      [WebMethod] 
      public string GetImage() 
      { 
        return "Image"; 
      } 
   } 

  public partial class Services : Services.IService 
  { 
    [WebMethod] 
    public string User() 
    { 
        return "User"; 
    } 
  } 
} 
riffnl
With partial classes he will not be able to use Proxy.UserService.User and Proxy.ImageService.GetImage. He will still have Proxy.User() and Proxy.GetImage(). Right?
Taras B
right - but it will allow mutiple class-files if want to logically group your functions.. I already mentioned: "You can not bind multiple classes to a single asmx" :-)
riffnl