473,320 Members | 1,580 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,320 software developers and data experts.

Using custom data types

In my web service project I've imported an assembly (that I also have
the source to) that contains structs that are serializable. I've
created some web service methods that return and take as parameters
some of these structures. When adding a web reference to a client that
consumes these web services, reference.cs doesn't contain a definition
for any of the structures in the assembly. I know I can add a
reference to the assembly directly in the client project to make it
work, but is there a way that I can make it work without doing this?
How can I expose these structures so they are part of the wsdl file
and thus have proxy stubs created for them? I would like clients to be
able to use these web services without having to download and add a
reference to their project. Thanks.

Matt
Nov 21 '05 #1
3 2696
Matt,

Yes it's possible.

Here is an example --- WebService --- Service1.asmx.cs file looks like ---

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace WebService1
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

[WebMethod]
public MyStruct HelloStruct()
{
MyStruct str = new MyStruct();
str.message = "Hello World !" ;
return str ;
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion
}

public struct MyStruct
{
public string message;
}
}

.... The client application will call the above as ...

localhost.Service1 svc = new WindowsApplication1.localhost.Service1() ;
localhost.MyStruct str = svc.HelloStruct() ;
MessageBox.Show(str.message) ;
If instead of a struct you wish to a class; you will have to specify set
accessors for all public properties. Need I mention, the logic of the class
doesn't come thru WSDL.

Regards,

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik

"Matt D" <md**********@yahoo.com> wrote in message
news:is********************************@4ax.com...
In my web service project I've imported an assembly (that I also have
the source to) that contains structs that are serializable. I've
created some web service methods that return and take as parameters
some of these structures. When adding a web reference to a client that
consumes these web services, reference.cs doesn't contain a definition
for any of the structures in the assembly. I know I can add a
reference to the assembly directly in the client project to make it
work, but is there a way that I can make it work without doing this?
How can I expose these structures so they are part of the wsdl file
and thus have proxy stubs created for them? I would like clients to be
able to use these web services without having to download and add a
reference to their project. Thanks.

Matt

Nov 21 '05 #2
Sahil,
Thanks for replying to my post. I do understand that it is possible
for this to work if MyStruct is in the same source file as the web
service. But is it possible for it to work if MyStruct is in a
separate assembly referenced by the web service without requiring the
client to download and add a reference to that same assembly? Thanks
again.

Matt

On Sun, 10 Oct 2004 14:57:19 -0400, "Sahil Malik"
<co*****************@nospam.com> wrote:
Matt,

Yes it's possible.

Here is an example --- WebService --- Service1.asmx.cs file looks like ---

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace WebService1
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

[WebMethod]
public MyStruct HelloStruct()
{
MyStruct str = new MyStruct();
str.message = "Hello World !" ;
return str ;
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion
}

public struct MyStruct
{
public string message;
}
}

... The client application will call the above as ...

localhost.Service1 svc = new WindowsApplication1.localhost.Service1() ;
localhost.MyStruct str = svc.HelloStruct() ;
MessageBox.Show(str.message) ;
If instead of a struct you wish to a class; you will have to specify set
accessors for all public properties. Need I mention, the logic of the class
doesn't come thru WSDL.

Regards,

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik


Nov 21 '05 #3
Hi Matt,

I share your opinion. I do not want my client to install any more
assemblies, so I wanted to know if you solved your problem after havint
written the enum or class in a separate assembly? Did it work?

I'm very interested in that because I've got the same problem as you,
instead of a enum, with a class.

Thanks in advance.

"Matt D" wrote:
Sahil,
Thanks for replying to my post. I do understand that it is possible
for this to work if MyStruct is in the same source file as the web
service. But is it possible for it to work if MyStruct is in a
separate assembly referenced by the web service without requiring the
client to download and add a reference to that same assembly? Thanks
again.

Matt

On Sun, 10 Oct 2004 14:57:19 -0400, "Sahil Malik"
<co*****************@nospam.com> wrote:
Matt,

Yes it's possible.

Here is an example --- WebService --- Service1.asmx.cs file looks like ---

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace WebService1
{
/// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

[WebMethod]
public MyStruct HelloStruct()
{
MyStruct str = new MyStruct();
str.message = "Hello World !" ;
return str ;
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion
}

public struct MyStruct
{
public string message;
}
}

... The client application will call the above as ...

localhost.Service1 svc = new WindowsApplication1.localhost.Service1() ;
localhost.MyStruct str = svc.HelloStruct() ;
MessageBox.Show(str.message) ;
If instead of a struct you wish to a class; you will have to specify set
accessors for all public properties. Need I mention, the logic of the class
doesn't come thru WSDL.

Regards,

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik


Nov 21 '05 #4

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

Similar topics

7
by: Blake T. Garretson | last post by:
I'm having some issues with decimal.Decimal objects playing nice with custom data types. I have my own matrix and rational classes which implement __add__ and __radd__. They know what to do with...
5
by: Abhilash.k.m | last post by:
This is regarding the session management using Out of proc session management(SQL SERVER). Among the samples below which one is better to set the session? 1. There are 20 session...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
4
by: CrispinH | last post by:
I'm building an application generator and within it a user can create a new property (for the class they are building). I'd like then to offer a list of Types - built-in and custom - for this new...
5
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
6
by: Scott M. Lyon | last post by:
As I mentioned in my other post, I'm attempting to, using COM Interop so I can update existing VB6 code to (for several specific functions) return a Hashtable from a .NET library. I've had...
4
by: =?Utf-8?B?cmtvemxpbg==?= | last post by:
Is it possible to remotely host custom types? Some background... We have an application that uses custom user controls as 'templates' for entering certain kinds of data. The application is...
11
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have...
1
by: jehugaleahsa | last post by:
Hello: I am experiencing performance related issues when my custom data structures work with value types. I use generics to prevent boxing wherever I can. For instance, I use IEqualityComparer,...
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.