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
"James Wong" <cp*****@commercialpress.com.hk.NO_SPAM> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Dear all,
I've a web service function and it contains a parameter in
System.Text.Encoding. I found that the data type of this parameter in
caller application becomes MyWebSvcName.Encoding (where "MyWebSvcName" is
the name of my web service). I don't know how to assign value to this
parameter. (I'm using VB.NET 2003.)
Here are some sample codes:
In web services:
<WebMethod(MessageName:="MyWebFunc")> _
Public Function MyWebFunc(ByVal objEncoding As System.Text.Encoding) As
Boolean
...
End Function
---
In caller application:
Dim blnBoolean As Boolean
blnBoolean = MyWebSvcName.MyWebFunc(Text.Encoding.GetEncoding(" BIG5"))
---
The IDE shows that datatype of System.Text.Encoding cannot convert to
MyWebSvcName.Encoding.
Does anybody have idea on this issue? Thanks for your attention and
kindly help!
Regards,
James Wong