473,749 Members | 2,636 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.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

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

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**********@p leasejippii.fi> ¦b¶l¥ó
news:%2******** ********@tk2msf tngp13.phx.gbl ¤¤¼¶¼g...
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

Nov 21 '05 #3

"James Wong" <cp*****@commer cialpress.com.h k.NO_SPAM> wrote in message
news:uz******** ******@TK2MSFTN GP10.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.Enc oding, 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**********@p leasejippii.fi> ¦b¶l¥ó
news:ey******** ********@TK2MSF TNGP10.phx.gbl ¤¤¼¶¼g...

"James Wong" <cp*****@commer cialpress.com.h k.NO_SPAM> wrote in message
news:uz******** ******@TK2MSFTN GP10.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.Enc oding, 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
2436
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: "pva:0.05:101214:pa7735tH:inv_desc=205308:shp_Email=petera_gudzon.net:lang =ru:shp_PaymentNo=20040825205308:shp_UserID=pva:shp_Price=2.95:shp_HostPlan= BU:shp_Term=2"
0
1563
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 (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:
0
2312
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 consume it with a C# application, I get the following runtime error from C#: Cannot assign object of type System.Xml.XmlNode to an object of type ConsoleApplication1.com.hilton.crmdev.SummaryType. Below is the Perl code that generates the hash,...
4
6027
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 extension. The code like this: public string HelloWorld() { return "Hello World.";
16
4926
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 Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
7
4089
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 someone will be able to make suggestions anyway. I'm using .NET, the server is using Axis. The web method I'm calling returns a simple complex type with two properties - a string and an int. In the soap envelope, these are set to values fine,...
1
2164
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 it in my smartphone application, it will work the first time and return ther query set, however when i try it again i get the following error : "Server found request content type to be 'text/html; charset=Windows-1252', but expected 'text/xml'."
5
2707
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 services at ws.mycompany.com. We have properly installed the server certificate on the client machine. When the client try to connect to our secure webservice at https:\\ws.mycompany.com we have the foolwing error: System.Net.WebException: The...
5
19599
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 having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
0
8997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9389
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2218
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.