Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Prob using a custom type in asp.net webservice

Reply
Thread Tools

Prob using a custom type in asp.net webservice

 
 
Brian Steiner
Guest
Posts: n/a
 
      01-18-2005
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?


 
Reply With Quote
 
 
 
 
Brian Steiner
Guest
Posts: n/a
 
      01-20-2005
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(Namespac e="mynamespace")]
public class Class1
{
public string s;
}

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

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

When I deserialize the proxy class Class3 i get:

<Class3 xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="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?

>
>



 
Reply With Quote
 
 
 
 
Elroyskimms
Guest
Posts: n/a
 
      01-21-2005
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/mess...3760455&p=1121
Thanks in advance for your help,

-Elroyskimms

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Audio prob that's more than a sound card prob LineOut Computer Support 2 04-19-2008 02:30 PM
Error Consuming Web Service from WIndows application when WebService is using Custom Service Account ( Create an Application Pool with a Custom Identity) DNB ASP .Net Security 1 01-22-2008 09:08 PM
Error Consuming Web Service from WIndows application when WebService is using Custom Service Account ( Create an Application Pool with a Custom Identity) DNB ASP .Net Web Services 1 01-20-2008 01:47 PM
Error connection using webservice locally (3 webservice in balanci Roberto Giorgetti ASP .Net Web Services 0 06-13-2006 06:40 PM
Printer prob and also networking prob Gareth not NLL or anybody else. Computer Support 2 01-02-2004 07:48 PM



Advertisments