The reason why you cannot see the second public class is because your code
does not use the second class in any way to the client. If you want to have
the second class be visible with your client (ie. defined in the WSDL), you
will need to:
1. Use Class2 in your class somewhere and return that to the client.
2. Define your own XSD/WSDL to explicitly define Class2 in the data schema
for your web service.
Here's my test code:
The Web Service Method
[WebMethod]
public Class1 HelloWorld()
{
Class1 c = new Class1();
c.x = 5;
Class2 c2 = new Class2();
c2.y = 10;
return c;
}
Class Definition
namespace WebService1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
public int x;
public Class1()
{
//
// TODO: Add constructor logic here
//
}
}
public class Class2
{
public int y;
}
}
The WSDL for this Web Service
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="http://tempuri.org/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
targetNamespace="http://tempuri.org/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<s:schema elementFormDefault="qualified"
targetNamespace="http://tempuri.org/">
<s:element name="HelloWorld">
<s:complexType />
</s:element>
<s:element name="HelloWorldResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult"
type="s0:Class1" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="Class1">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="x" type="s:int" />
</s:sequence>
</s:complexType>
</s:schema>
</types>
<message name="HelloWorldSoapIn">
<part name="parameters" element="s0:HelloWorld" />
</message>
<message name="HelloWorldSoapOut">
<part name="parameters" element="s0:HelloWorldResponse" />
</message>
<portType name="Service1Soap">
<operation name="HelloWorld">
<input message="s0:HelloWorldSoapIn" />
<output message="s0:HelloWorldSoapOut" />
</operation>
</portType>
<binding name="Service1Soap" type="s0:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld"
style="document" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="Service1">
<port name="Service1Soap" binding="s0:Service1Soap">
<soap:address location="http://localhost/WebService1/Service1.asmx" />
</port>
</service>
</definitions>
Notice the <types> section does not contain a declaration for Class2. The
auto generated WSDL will only generate a data definition for a type if it is
used as part of the interface definition.
Eric
"Burak" <bu*********@xpandcorp.com> wrote in message
news:b1**************************@posting.google.c om...
Hello,
I have a web service that has a two user defined public classes. For
sake of brevity, I'll write them as follows
Public Class Service1
Public Class Class1
Public x as integer
End Class
Public Class Class2
Public y as string
End Class
<WebMethod()> _
Public Function GetValue() As Class1
dim c1 as new class1
c1.x = 10
Return c1
End Function
End Class
When I create an instance of this webservice on the client, I can
only see Class1 and not Class2, even though both are public classes. I
suspect this is because I am returning a variable of type Class1.
I even put <Serializable()> in front of Class2, but I still couldn't
see it from the client side.
How do you make all public classes of a web service accessible from
the client?
Thank you,
Burak