Trying to return a C# Class that conforms to a schema

M

Mike Lopez

Hello.

I'm missing something, I just know it.

I'm writing a web service and I'm new at this.

Scenario:

I got a Request and a Response XSD from a business partner. I used XSD.exe
to generate the C# classes.
I created a C# ASP Web Application. I added the generated classes to the
project. I then created a WebMethod whose return type is the generated
class that corresponds to the Response root element. I created variables for
each generated class, initialized each instance, and tried to to return the
"root" class instance (just to see if the XML generated corresponds to the
Response schema), but get an error. I posted the error in a previous
posting. Basically it looks like the runtime is compiling something, giving
it a random name, and then cannot find it.

So, at this point I don't know how to structure my project, I don't know
what the generated classes are good for (I thought I did) because based on
the error I'm misusing them, and I don't know how to return my user defined
class so that it corresponds to the schema.

Now, I've been all over MSDN, Googled, MSN Searched (Google is still better
at this point), went to Border's Books and read through everything they
have, and all I can find about WebServices are simple examples that return
"string, int, double". Really, nothing more than "Hello World" examples.

If "http://tempuri.org" is satisfactory for someone then it's no wonder
everyone says they're so simple to create. But that's not reality.

Where are the sample projects that show the structure of a solution that
does what I need to do? I know I'm not alone in the universe!

What am I missing? Do I need to use SOAP in some way?

Someone please point me in the right direction.

Thanks in advance,

Mike
 
D

DalePres

In ASP.Net, web services generally can only return value types and some
serializable object classes that Microsoft has chosen to implement the code
for. For instance, they can return a DataSet, because Microsoft implemented
it, but they cannot return a DataTable.

If you add an instance of the XMLInclude attribute to your return type class
and to each class that your return type references, that will often solve
the problem.

Hope this helps,

DalePres
MCAD, MCDBA, MCSE
 
D

Dilip Krishnan

Hello DalePres,
I think what you're probably having a problem with is the return type
attributes... try using an attribute like this in your web method

[return : XmlElement("name-of-the-xml-element", Namespace="namespace-from-the-generated-class")]
[WebMethod]
public GeneratedClass SomeMethod()
{
return GeneratedClassInstance;
}

HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
 
M

Mike Lopez

Hi, Dilip. Thanks for responding.

Let me ask you, where is the documentation on the "[result:" attribute? I
cannot find it anywhere.

This is what I was talking about when I said "I know I'm missing something".

Thanks again,

Mike

Dilip Krishnan said:
Hello DalePres,
I think what you're probably having a problem with is the return type
attributes... try using an attribute like this in your web method

[return : XmlElement("name-of-the-xml-element",
Namespace="namespace-from-the-generated-class")]
[WebMethod]
public GeneratedClass SomeMethod() {
return GeneratedClassInstance;
}

HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
In ASP.Net, web services generally can only return value types and
some serializable object classes that Microsoft has chosen to
implement the code for. For instance, they can return a DataSet,
because Microsoft implemented it, but they cannot return a DataTable.

If you add an instance of the XMLInclude attribute to your return type
class and to each class that your return type references, that will
often solve the problem.

Hope this helps,

DalePres
MCAD, MCDBA, MCSE
 
D

Dilip Krishnan

Hello Mike,
http://msdn.microsoft.com/library/d...ry/en-us/csspec/html/vclrfcsharpspec_17_2.asp
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
Hi, Dilip. Thanks for responding.

Let me ask you, where is the documentation on the "[result:"
attribute? I cannot find it anywhere.

This is what I was talking about when I said "I know I'm missing
something".

Thanks again,

Mike

Hello DalePres,
I think what you're probably having a problem with is the return type
attributes... try using an attribute like this in your web method
[return : XmlElement("name-of-the-xml-element",
Namespace="namespace-from-the-generated-class")]
[WebMethod]
public GeneratedClass SomeMethod() {
return GeneratedClassInstance;
}
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
In ASP.Net, web services generally can only return value types and
some serializable object classes that Microsoft has chosen to
implement the code for. For instance, they can return a DataSet,
because Microsoft implemented it, but they cannot return a
DataTable.

If you add an instance of the XMLInclude attribute to your return
type class and to each class that your return type references, that
will often solve the problem.

Hope this helps,

DalePres
MCAD, MCDBA, MCSE
Hello.

I'm missing something, I just know it.

I'm writing a web service and I'm new at this.

Scenario:

I got a Request and a Response XSD from a business partner. I used
XSD.exe
to generate the C# classes.
I created a C# ASP Web Application. I added the generated classes
to
the
project. I then created a WebMethod whose return type is the
generated
class that corresponds to the Response root element. I created
variables
for each generated class, initialized each instance, and tried to
to
return the "root" class instance (just to see if the XML generated
corresponds to the Response schema), but get an error. I posted the
error
in a previous posting. Basically it looks like the runtime is
compiling
something, giving it a random name, and then cannot find it.
So, at this point I don't know how to structure my project, I don't
know what the generated classes are good for (I thought I did)
because based on the error I'm misusing them, and I don't know how
to
return my user defined class so that it corresponds to the schema.
Now, I've been all over MSDN, Googled, MSN Searched (Google is
still better at this point), went to Border's Books and read
through everything they have, and all I can find about WebServices
are simple examples that return "string, int, double". Really,
nothing more than "Hello World" examples.

If "http://tempuri.org" is satisfactory for someone then it's no
wonder everyone says they're so simple to create. But that's not
reality.

Where are the sample projects that show the structure of a solution
that does what I need to do? I know I'm not alone in the universe!

What am I missing? Do I need to use SOAP in some way?

Someone please point me in the right direction.

Thanks in advance,

Mike
 
M

MikeL

Thanks Dilip. The mystery is gone.

Is there a VB.Net equivalent of these attributes?

Thanks again,

Mike

Dilip Krishnan said:
Hello Mike,
http://msdn.microsoft.com/library/d...ry/en-us/csspec/html/vclrfcsharpspec_17_2.asp
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
Hi, Dilip. Thanks for responding.

Let me ask you, where is the documentation on the "[result:"
attribute? I cannot find it anywhere.

This is what I was talking about when I said "I know I'm missing
something".

Thanks again,

Mike

Hello DalePres,
I think what you're probably having a problem with is the return type
attributes... try using an attribute like this in your web method
[return : XmlElement("name-of-the-xml-element",
Namespace="namespace-from-the-generated-class")]
[WebMethod]
public GeneratedClass SomeMethod() {
return GeneratedClassInstance;
}
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
In ASP.Net, web services generally can only return value types and
some serializable object classes that Microsoft has chosen to
implement the code for. For instance, they can return a DataSet,
because Microsoft implemented it, but they cannot return a
DataTable.

If you add an instance of the XMLInclude attribute to your return
type class and to each class that your return type references, that
will often solve the problem.

Hope this helps,

DalePres
MCAD, MCDBA, MCSE
Hello.

I'm missing something, I just know it.

I'm writing a web service and I'm new at this.

Scenario:

I got a Request and a Response XSD from a business partner. I used
XSD.exe
to generate the C# classes.
I created a C# ASP Web Application. I added the generated classes
to
the
project. I then created a WebMethod whose return type is the
generated
class that corresponds to the Response root element. I created
variables
for each generated class, initialized each instance, and tried to
to
return the "root" class instance (just to see if the XML generated
corresponds to the Response schema), but get an error. I posted the
error
in a previous posting. Basically it looks like the runtime is
compiling
something, giving it a random name, and then cannot find it.
So, at this point I don't know how to structure my project, I don't
know what the generated classes are good for (I thought I did)
because based on the error I'm misusing them, and I don't know how
to
return my user defined class so that it corresponds to the schema.
Now, I've been all over MSDN, Googled, MSN Searched (Google is
still better at this point), went to Border's Books and read
through everything they have, and all I can find about WebServices
are simple examples that return "string, int, double". Really,
nothing more than "Hello World" examples.

If "http://tempuri.org" is satisfactory for someone then it's no
wonder everyone says they're so simple to create. But that's not
reality.

Where are the sample projects that show the structure of a solution
that does what I need to do? I know I'm not alone in the universe!

What am I missing? Do I need to use SOAP in some way?

Someone please point me in the right direction.

Thanks in advance,

Mike
 
D

Dilip Krishnan

Hello MikeL,

After the *As*

Public Function SomeFunction(<System.Xml.Serialization.XmlElementAttribute([Namespace]:="http://someuri")>
ByVal SomeClass As someclass) As <System.Xml.Serialization.XmlElementAttribute("SomeReturn",
[Namespace]:="http://someuri")> SomeReturnType
End Function



HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
Thanks Dilip. The mystery is gone.

Is there a VB.Net equivalent of these attributes?

Thanks again,

Mike

Hello Mike,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cssp
ec/html/vclrfcsharpspec_17_2.asp

HTH

Regards,

Dilip Krishnan

MCAD, MCSD.net

dkrishnan at geniant dot com

http://www.geniant.com
Hi, Dilip. Thanks for responding.

Let me ask you, where is the documentation on the "[result:"
attribute? I cannot find it anywhere.

This is what I was talking about when I said "I know I'm missing
something".

Thanks again,

Mike


Hello DalePres,
I think what you're probably having a problem with is the return
type
attributes... try using an attribute like this in your web method
[return : XmlElement("name-of-the-xml-element",
Namespace="namespace-from-the-generated-class")]
[WebMethod]
public GeneratedClass SomeMethod() {
return GeneratedClassInstance;
}
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
In ASP.Net, web services generally can only return value types and
some serializable object classes that Microsoft has chosen to
implement the code for. For instance, they can return a DataSet,
because Microsoft implemented it, but they cannot return a
DataTable.

If you add an instance of the XMLInclude attribute to your return
type class and to each class that your return type references,
that will often solve the problem.

Hope this helps,

DalePres
MCAD, MCDBA, MCSE
Hello.

I'm missing something, I just know it.

I'm writing a web service and I'm new at this.

Scenario:

I got a Request and a Response XSD from a business partner. I
used
XSD.exe
to generate the C# classes.
I created a C# ASP Web Application. I added the generated classes
to
the
project. I then created a WebMethod whose return type is the
generated
class that corresponds to the Response root element. I created
variables
for each generated class, initialized each instance, and tried to
to
return the "root" class instance (just to see if the XML
generated
corresponds to the Response schema), but get an error. I posted
the
error
in a previous posting. Basically it looks like the runtime is
compiling
something, giving it a random name, and then cannot find it.
So, at this point I don't know how to structure my project, I
don't
know what the generated classes are good for (I thought I did)
because based on the error I'm misusing them, and I don't know
how
to
return my user defined class so that it corresponds to the
schema.
Now, I've been all over MSDN, Googled, MSN Searched (Google is
still better at this point), went to Border's Books and read
through everything they have, and all I can find about
WebServices
are simple examples that return "string, int, double". Really,
nothing more than "Hello World" examples.
If "http://tempuri.org" is satisfactory for someone then it's no
wonder everyone says they're so simple to create. But that's not
reality.

Where are the sample projects that show the structure of a
solution that does what I need to do? I know I'm not alone in the
universe!

What am I missing? Do I need to use SOAP in some way?

Someone please point me in the right direction.

Thanks in advance,

Mike
 
D

Dan Rogers

I'm guessing after all of these responses, you're still stuck.

This not being able to find the compiled serializer tells me there's a
permissions problem. Did you change the identity or restrict the
permissions of the .NET runtime?

The XSD.exe tool already adds the appropriate markup to the generated
classes, so you don't have to do (usually) the XMLInclude and returns:
markup. That is used to serialze when no Xml*Attribute markup has been
added to the types you want to serialize.

--------------------
Message-ID: <[email protected]>
From: Dilip Krishnan <[email protected]>
Subject: Re: Trying to return a C# Class that conforms to a schema
References: <[email protected]>
Mime-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=iso-8859-1; format=flowed
X-Newsreader: JetBrains Omea Reader 439.21
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
Date: Mon, 07 Feb 2005 20:28:06 -0800
NNTP-Posting-Host: c-24-2-24-166.client.comcast.net 24.2.24.166
Lines: 1
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.aspnet.webservices:28001
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices

Hello MikeL,

After the *As*

Public Function SomeFunction(<System.Xml.Serialization.XmlElementAttribute([Namespace]:="htt
p://someuri")>
ByVal SomeClass As someclass) As <System.Xml.Serialization.XmlElementAttribute("SomeReturn",
[Namespace]:="http://someuri")> SomeReturnType
End Function



HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
Thanks Dilip. The mystery is gone.

Is there a VB.Net equivalent of these attributes?

Thanks again,

Mike

Hello Mike,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cssp
ec/html/vclrfcsharpspec_17_2.asp

HTH

Regards,

Dilip Krishnan

MCAD, MCSD.net

dkrishnan at geniant dot com

http://www.geniant.com

Hi, Dilip. Thanks for responding.

Let me ask you, where is the documentation on the "[result:"
attribute? I cannot find it anywhere.

This is what I was talking about when I said "I know I'm missing
something".

Thanks again,

Mike


Hello DalePres,
I think what you're probably having a problem with is the return
type
attributes... try using an attribute like this in your web method
[return : XmlElement("name-of-the-xml-element",
Namespace="namespace-from-the-generated-class")]
[WebMethod]
public GeneratedClass SomeMethod() {
return GeneratedClassInstance;
}
HTH
Regards,
Dilip Krishnan
MCAD, MCSD.net
dkrishnan at geniant dot com
http://www.geniant.com
In ASP.Net, web services generally can only return value types and
some serializable object classes that Microsoft has chosen to
implement the code for. For instance, they can return a DataSet,
because Microsoft implemented it, but they cannot return a
DataTable.

If you add an instance of the XMLInclude attribute to your return
type class and to each class that your return type references,
that will often solve the problem.

Hope this helps,

DalePres
MCAD, MCDBA, MCSE
Hello.

I'm missing something, I just know it.

I'm writing a web service and I'm new at this.

Scenario:

I got a Request and a Response XSD from a business partner. I
used
XSD.exe
to generate the C# classes.
I created a C# ASP Web Application. I added the generated classes
to
the
project. I then created a WebMethod whose return type is the
generated
class that corresponds to the Response root element. I created
variables
for each generated class, initialized each instance, and tried to
to
return the "root" class instance (just to see if the XML
generated
corresponds to the Response schema), but get an error. I posted
the
error
in a previous posting. Basically it looks like the runtime is
compiling
something, giving it a random name, and then cannot find it.
So, at this point I don't know how to structure my project, I
don't
know what the generated classes are good for (I thought I did)
because based on the error I'm misusing them, and I don't know
how
to
return my user defined class so that it corresponds to the
schema.
Now, I've been all over MSDN, Googled, MSN Searched (Google is
still better at this point), went to Border's Books and read
through everything they have, and all I can find about
WebServices
are simple examples that return "string, int, double". Really,
nothing more than "Hello World" examples.
If "http://tempuri.org" is satisfactory for someone then it's no
wonder everyone says they're so simple to create. But that's not
reality.

Where are the sample projects that show the structure of a
solution that does what I need to do? I know I'm not alone in the
universe!

What am I missing? Do I need to use SOAP in some way?

Someone please point me in the right direction.

Thanks in advance,

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top