470,594 Members | 1,134 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

Problem in passing encoding information to WebServices 2

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

Nov 21 '05 #1
5 3309
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

Nov 21 '05 #2
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

"Sami Vaaraniemi" <sa**********@pleasejippii.fi> 在郵件
news:%2****************@tk2msftngp13.phx.gbl 中撰寫...
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

Nov 21 '05 #3

"James Wong" <cp*****@commercialpress.com.hk.NO_SPAM> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...
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


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
Nov 21 '05 #4
Hi Sami,

Thanks again for your additional information!

Regards,
James Wong

"Sami Vaaraniemi" <sa**********@pleasejippii.fi> 在郵件
news:ey****************@TK2MSFTNGP10.phx.gbl 中撰寫...

"James Wong" <cp*****@commercialpress.com.hk.NO_SPAM> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...
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


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

Nov 21 '05 #5
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...b;en-us;326791

HOW TO: Change Types Used in Proxy Classes That Are Generated with Wsdl.exe
http://support.microsoft.com/default...b;en-us;326790

Darwin Abustan
Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Peter Afonin | last post: by
reply views Thread by Peter Conrey | last post: by
4 posts views Thread by pepcag | last post: by
1 post views Thread by Mike | last post: by
5 posts views Thread by Dany C. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.