473,508 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3482
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> ¦b¶l¥ó
news:%2****************@tk2msftngp13.phx.gbl ¤¤¼¶¼g...
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> ¦b¶l¥ó
news:ey****************@TK2MSFTNGP10.phx.gbl ¤¤¼¶¼g...

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2402
by: Peter Afonin | last post by:
Hello, I'm struggling with the string conversion to MD5 which I've never user before. I have a string that I need to encode which looks approximately like this: ...
0
1548
by: James Wong | last post by:
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...
0
2298
by: Peter Conrey | last post by:
I have a perl web service (using SOAP::Lite) with a method called "Detail" that returns a strucure (hash reference to be exact). It works fine when consumed by a Perl client, but when I try to...
4
6005
by: pepcag | last post by:
I used http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconalteringsoapmessageusingsoapextensions.asp as a template to create a very simple web method with soap...
16
4870
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
7
4061
by: Danny Tuppeny | last post by:
Hi All, I've been going through Google Groups, but nothing seems to quite match my problem. It's hard to post a WSDL or anything at the moment (it's not my service, I'm just using it), but maybe...
1
2149
by: Mike | last post by:
Hi all, I have written a webservice which I am using in my smartphone applicaiton. I have tried the webservice with a WinForms client and it works time and time again perfectly. When I include...
5
2687
by: Dany C. | last post by:
We have install a valid SSL certificate issued to www.mycompany.com on our web server running IIS 6.0 / win2003 SP1. Then we have created a sub domain pointing to the same server for our web...
5
19560
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7328
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7049
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7499
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5631
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3199
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.