473,289 Members | 1,917 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,289 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 4193
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.