Reputation: 41
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";
}
}
}
Upvotes: 0
Views: 3231
Reputation: 3183
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";
}
}
}
Upvotes: 1
Reputation: 1038930
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.
Upvotes: 4