简体   繁体   中英

Can't access method in class in web service

I have an asp web service that contains a class which has a function inside of it, but I can't seem to access that function when I'm referencing it in my winforms project. All other aspects of my webservice are working and everything updates according to my changes. Here is the code in my web service that illustrates the problem I'm having. In the example, if I were to create an instance of ItemOrder from a winform project referencing this web service, I would not be able to call AddItem(...).

[WebService(Namespace = "http://myurl.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class MyWebService : System.Web.Services.WebService
{

    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://myurl.com/")]
    public class ItemOrder
    {
        public string OrderNumber = "";
        public DateTime OrderDate = DateTime.Now;
        public decimal TotalCost = 0M;

        internal List<Item> items = new List<Item>();

        [WebMethod]
        public void AddItem(string reference)
        {
            Item item = new Item();
            item.ItemReference = reference;
            items.Add(item);
        }
    }

    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://myurl.com/")]
    public class Item
    {
        public decimal Cost = 0M;
        public decimal Price = 0M;
        public string ItemReference = "";
    }
}

The code above is a simplified example, not my entire situation. My problem is that I cannot call any methods for classes defined within the web service class. I can call a method defined in the root web service class (MyWebService) no problem. If anyone has any ideas why this is or if you could point me in the right direction, that would be appreciated.

Web services cannot serialize code so methods in your classes will not be available to the client proxy (and if you have code in private methods it will not execute). Objects serialized via this method are only data transfer objects - dumb properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM