Accessing Public classes in your Webservice from Clients

Recently I struggled a lot to figure out how to access classes that are public in my webservice namespace, from the client (that was making the webservice method calls)

I had a Public class called “Details” in my webservice and I had a method which would return an ArrayList of objects of type “Details” to the client. But I could never access the class “Details” from the client.

Here is what I finally did:

I had a webservice called TestWebService which had many public classes in its namespace. Here is how the namespace looked:

namespace Test.TestWebService

{

    public class Details

    {

        public Details() { }

        ...

    }

    public class TestWebService

    {

        ...

       

       [WebMethod]

 public ArrayList GetDetails()à Client couldn’t access the class “Details”

       public List<Details> GetDetails()à Client could access the class “Details”

       {   

            ArrayList list = new ArrayList(); 

            List<Details> details = new List<Details>();

 

            ///Do all processing

            ///Let us assume that this "list" gets filled up dynamically

            ...

            return list; à Client couldn’t access the class “Details”

            return details; à Client could access the class “Details”

      }

    }

}

So on the client side (after changing the return type) I tried to access the method this way:

test.TestWebService svc = new ConsoleApplication3.test.TestWebService();

test.Details[] details = svc.GetDetails(1);

 

So basically I could never access “Details” from my client until it got used somewhere in the web method signature (either as an input parameter or as a return value).

Hope this helps.

 


(This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at https://www.microsoft.com/info/cpyright.htm)