473,395 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

Similar topics

15
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.