Passing an object of type System.Text.Enc oding 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.Enc oding 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(type of(System.Text. UnicodeEncoding ))]
[XmlInclude(type of(System.Text. AsciiEncoding))]
// etc...
public bool MyWebFunc(strin g 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(strin g encodingName)
{
try
{
System.Text.Enc oding enc =
System.Text.Enc oding.GetEncodi ng(encodingName );
}
catch (Exception ex)
{
// not a valid encoding...
throw ex;
}
}
hth,
Sami
"James Wong" <cp*****@commer cialpress.com.h k.NO_SPAM> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Dear all,
I've a web service function and it contains a parameter in
System.Text.Enc oding. I found that the data type of this parameter in
caller application becomes MyWebSvcName.En coding (where "MyWebSvcNa me" 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(Mess ageName:="MyWeb Func")> _
Public Function MyWebFunc(ByVal objEncoding As System.Text.Enc oding) As
Boolean
...
End Function
---
In caller application:
Dim blnBoolean As Boolean
blnBoolean = MyWebSvcName.My WebFunc(Text.En coding.GetEncod ing("BIG5"))
---
The IDE shows that datatype of System.Text.Enc oding cannot convert to
MyWebSvcName.En coding.
Does anybody have idea on this issue? Thanks for your attention and
kindly help!
Regards,
James Wong