473,387 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do you make all public classes of a web service accessible from client?

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
Nov 21 '05 #1
2 4198
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

Nov 21 '05 #2
2nd time tonight. The answer is to apply the XMLInclude attribute to your
WebMethod:

[WebMethod()]
[XmlInclude(typeof(Class2))]
Public Class1 GetValue()
{
'Class1 implementation code here
}

Dale
"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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike van Lammeren | last post by:
Hello! I am totally stuck on this problem. I have a web service written in Perl, which uses Frontier::RPC2, and runs on MS IIS 4. I can access the web service using a client written in either...
5
by: Khalique | last post by:
Hi everyone, I Hope that someone will be able to give me a hint to the solution to my problem. I have developed a web service (vb.net) that needs to access the folders / files and copy files to...
2
by: Howard Postley | last post by:
This seems like it's probably a pretty basic question but is there a way to publish multiple classes from a single web service URL? Using VS.NET, I create a project, FOO and add a web service,...
34
by: Asfand Yar Qazi | last post by:
Hi, I'm creating a library where several classes are intertwined rather tightly. I'm thinking of making them all use pimpls, so that these circular dependancies can be avoided easily, and I'm...
1
by: D. | last post by:
Hi, i come from classic asp and i'm a little confused with variable declaration in VB. I read: "A Public variable is accessible from any place within the module it was declared or other...
8
by: Al | last post by:
I'd like to create Class Library in VB 2005, which has a property accessible by external programs. I decided to include 1 Class with 1 property in this project. I placed this code in Class:...
3
by: Arpan | last post by:
Web Services make use of proxy classes whose methods & properties are accessed in exactly the same way as how a normal class' methods & properties are accessed. So what for does ASP.NET generate...
3
by: =?Utf-8?B?Y2FsZGVyYXJh?= | last post by:
Dear all, I have one question base on a choice of having a public interfcace access compare to public class member. IN other word let say that I have a public interface named ImyInterface with...
3
by: kkao77 | last post by:
can you show me in more detail? I have same problem where on the page it's https://service.premilance.com/Company.svc, but the svcutil tells me to get it from https://pserver1/Company.svc?wsdl...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.