Passing an object of type System.Text.Encoding to a Web Service is
problematic because the proxy will contain a copy of that type. The copy is
an abstract class with no properties and is pretty much useless. To see
this, take a look at the proxy code in reference.cs.
Now you can actually pass objects of type System.Text.Encoding to a Web
Service if you add XmlInclude attributes to the web method. However this
would be a bit unpractical as you would have to list all Encoding types
you're expecting like so:
[WebMethod]
[XmlInclude(typeof(System.Text.UnicodeEncoding))]
[XmlInclude(typeof(System.Text.AsciiEncoding))]
// etc...
public bool MyWebFunc(string encodingName)
{
...
}
You would also have to modify the generated proxy accordingly, which in
general is a bad idea as the modifications are lost as soon as you
regenerate the proxy.
An easy work-around to the problem is to use a simple string parameter like
so:
[WebMethod]
public bool MyWebFunc(string encodingName)
{
try
{
System.Text.Encoding enc =
System.Text.Encoding.GetEncoding(encodingName);
}
catch (Exception ex)
{
// not a valid encoding...
throw ex;
}
}
hth,
Sami
> Dear all,
>
[quoted text clipped - 31 lines]
> Regards,
> James Wong
James Wong - 04 Aug 2004 04:44 GMT
Hi Sami,
Thanks for your reply and the word-around works in my case. However, do you
think whether this behavior is a "should-be in this way" in design of proxy?
Regards,
James Wong
> Passing an object of type System.Text.Encoding to a Web Service is
> problematic because the proxy will contain a copy of that type. The copy is
[quoted text clipped - 39 lines]
> hth,
> Sami
Sami Vaaraniemi - 04 Aug 2004 08:21 GMT
> Hi Sami,
>
[quoted text clipped - 3 lines]
> Regards,
> James Wong
Well, the short answer is 'yes'.
Web Services are essentially about passing around XML documents. If you try
to send an object of type such as System.Text.Encoding, it gets converted to
something that can be passed over in XML.
If you really want to use the same type between two remote application end
points, then .NET remoting might be better suited for your needs.
Regards,
Sami
James Wong - 05 Aug 2004 02:10 GMT
Hi Sami,
Thanks again for your additional information!
Regards,
James Wong
> > Hi Sami,
> >
[quoted text clipped - 17 lines]
> Regards,
> Sami
Darwin Abustan[MSFT] - 21 Dec 2004 00:32 GMT
I second Sami's workaround for to James' issue. The following are just some references that researchers may find useful over similar issues.
INFO: Supported Data Types for Web Services That Are Called Through the SOAP Protocol or the HTTP Protocol (326791)
http://support.microsoft.com/default.aspx?scid=kb;en-us;326791
HOW TO: Change Types Used in Proxy Classes That Are Generated with Wsdl.exe
http://support.microsoft.com/default.aspx?scid=kb;en-us;326790
Darwin Abustan
Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights