Prob using a custom type in asp.net webservice

B

Brian Steiner

I have the following sample asp.net webservice:

....
namespace x
{
[WebService(Namespace="mynamespace")]
public class WS : System.Web.Services.WebService
{
...
public class Class1
{
public string s;
}
public class Class2
{
public string s;
}
public class Class3
{
public string s;
public Class1 c1;
public Class2 c2;
}

public string Test(Class3 c3)
{
}
}
}

When I use XmlSerializer to deserialize the webreference proxy for Class3,
it includes namespace attributes for Class3.s, Class3.c1, and Class3.c2. If
I set the namespace attribute of the webservice to "" and update the
webreference, the webreference proxy no longer works. How can I tell the
webservice to ignore the namespace attribute for all public types in Class3?
 
B

Brian Steiner

Thanks Christoph.

I tried both of your suggestions and the autogenerated webref proxy types
continue to define a namespace attrib. Here's an example of the webref
proxies:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="mynamespace")]
public class Class1
{
public string s;
}

[System.Xml.Serialization.XmlTypeAttribute(Namespace="mynamespace")]
public class Class2
{
public string s;
}

[System.Xml.Serialization.XmlTypeAttribute(Namespace="mynamespace")]
public class Class3
{
public string s;
public Class1 c1;
public Class2 c2;
}

When I deserialize the proxy class Class3 i get:

<Class3 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s xmlns="mynamespace"/>
<c1 xmlns="mynamespace">
<s/>
</c1>
<c2 xmlns="mynamespace">
<s/>
</c2>
</Class3>

When I deserialize the types in the webservice itself i get:

<Class3 ...>
<s/>
<c1>
<s/>
</c1>
<c2>
<s/>
</c2>
</Class3>

What I want to do is serialize Class3 in the webservice, deserialize it on
the client, and then submit it to the webservice method Test. The namespace
requirement on the proxy types is preventing me from doing this.

"Christoph Schittko [MVP]"
Brian,

You can't tell the web service class to "ignore" the namespace for all
fields. You have to override the parent's, i.e. the web service's XML
namespace setting on every field.

If you change the XML namespace settings on the web service or any of
the classes that occur as method parameters or return values, you always
have to re-generate the proxy class because you changed the XML wire
format. There is no way the original proxy can communicate with the
changed service.

Now, for your fields of Class3 not to have any namespace declarations
you can:

1)
Set the namespace on Class3 with the XmlType attribute:

[XmlType(Namespace="")]
public class Class3
{
public string s;
public Class1 c1;
public Class2 c2;
}

Or

2)
You can define the namespace of each field individually:

public class Class3
{
[XmlElement(Namespace="")]
public string s;
[XmlElement(Namespace="")]
public Class1 c1;
[XmlElement(Namespace="")]
public Class2 c2;
}

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko

-----Original Message-----

I have the following sample asp.net webservice:

...
namespace x
{
[WebService(Namespace="mynamespace")]
public class WS : System.Web.Services.WebService
{
...
public class Class1
{
public string s;
}
public class Class2
{
public string s;
}
public class Class3
{
public string s;
public Class1 c1;
public Class2 c2;
}

public string Test(Class3 c3)
{
}
}
}

When I use XmlSerializer to deserialize the webreference proxy for Class3,
it includes namespace attributes for Class3.s, Class3.c1, and Class3.c2.
If
I set the namespace attribute of the webservice to "" and update the
webreference, the webreference proxy no longer works. How can I tell the
webservice to ignore the namespace attribute for all public types in
Class3?
 
E

Elroyskimms

Christoph,

I've been looking for an answer to an ASP.Net problem and have not had
much luck. I've also seen you respond to similar issues as mine and at
least once, come very to close to answering the question. If you
wouldn't mind, could you please take a look at the following thread:

http://www.developersdex.com/vb/message.asp?r=3760455&p=1121
Thanks in advance for your help,

-Elroyskimms
 

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

Forum statistics

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

Latest Threads

Top