473,409 Members | 2,034 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,409 software developers and data experts.

How to return class with simple type props from Web Service?

I have the below simple class -

[Serializable()]
public class MyClass
{
protected string m_stName;
protected string m_stCode;
protected int m_iId;

public MyClass() {}

public string Name { /* get and set */ }
public string Code { /* get and set */ }
public int Id { /* get and set */ }
}

And a simple web service project with one web method -

[WebMethod]
public MyClass MyClass()
{
MyClass retVal = new MyClass();
retVal.Name = "My Class";
retVal.Id = 0;
retVal.Code = "MC 0";
return retVal;
}

When I try debugging (simple debug using ie as client in VS, maybe that is
the problem?), I get...
A first chance exception of type 'System.InvalidOperationException' occurred
in system.xml.dll

Additional information: The XML element named 'MyClass' from namespace
'http://tempuri.org/' references a method and a type. Change the method's
message name using WebMethodAttribute or change the type's root element
using the XmlRootAttribute.
<<

If I change the web method name to "getClass" so it isn't the same name as
the return type, I get...

A first chance exception of type 'System.ArgumentException' occurred in
mscorlib.dll

Additional information: Error binding to target method.
<<

Anyone have a link to a good example of returning a custom class with web
services? Been googling, haven't found one yet.

Thanks in advance!

Derrick
Nov 16 '05 #1
1 9461
Well, this code actually works fine if I create a stand alone solution. If
I create a new c# web service project and add it to a solution containing a
C# windows forms app and C# class library projects, then I get the error,
even with the simple HelloWorld method that is stock in new projects?

Anyone ever see that before?

Thanks!

Derrick
"Derrick" <de*********@excite.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
I have the below simple class -

[Serializable()]
public class MyClass
{
protected string m_stName;
protected string m_stCode;
protected int m_iId;

public MyClass() {}

public string Name { /* get and set */ }
public string Code { /* get and set */ }
public int Id { /* get and set */ }
}

And a simple web service project with one web method -

[WebMethod]
public MyClass MyClass()
{
MyClass retVal = new MyClass();
retVal.Name = "My Class";
retVal.Id = 0;
retVal.Code = "MC 0";
return retVal;
}

When I try debugging (simple debug using ie as client in VS, maybe that is
the problem?), I get...
A first chance exception of type 'System.InvalidOperationException' occurred in system.xml.dll

Additional information: The XML element named 'MyClass' from namespace
'http://tempuri.org/' references a method and a type. Change the method's
message name using WebMethodAttribute or change the type's root element
using the XmlRootAttribute.
<<

If I change the web method name to "getClass" so it isn't the same name as
the return type, I get...

A first chance exception of type 'System.ArgumentException' occurred in
mscorlib.dll

Additional information: Error binding to target method.
<<

Anyone have a link to a good example of returning a custom class with web
services? Been googling, haven't found one yet.

Thanks in advance!

Derrick

Nov 16 '05 #2

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

Similar topics

10
by: Don | last post by:
I want the server-side php script to return a browser page that is essentially a copy of the original client page that contained the <form> which referenced the php script in the first place....
0
by: Jim Hansen | last post by:
I re-installed Framework and now I am getting this error ClassBrowser. Most other page work just fine. Additionally, the debugger will not start from Visual Studio 2003.. Compilation Error...
2
by: Richard A. Wells | last post by:
All I wanted to do was implement a web service where I'd receive an XML document and return one in response. I'd already figured out how to use XmlReader and XmlWriter classes to do the XML work I...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
4
by: Steve Drake | last post by:
All, If you right click on a word doc, you can see and set the custom props for the document, how can this be done in C# (or any other lang) I don't want to automate word as this will be...
1
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive...
2
by: Mythran | last post by:
System.Drawing.SystemColors is a class with all static properties. Here is what my short-ranged goal is... I want to enumerate all of the SystemColors properties and print the name (using...
3
by: Chris Pratt | last post by:
I'm sorry to ask such a fundamental question, but is it possible to create a copy of an object in VB.Net 2005? I have an app which, on load, creates an instance of a class, into which it reads a...
2
by: she_prog | last post by:
I have a class derived from UserControl. I need to serialize an object of this class, but only some properties of it, as not all properties are serializable (some of the properties coming from...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.