Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / December 2004

Tip: Looking for answers? Try searching our database.

Problem in passing encoding information to WebServices 2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James Wong - 03 Aug 2004 02:07 GMT
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
Sami Vaaraniemi - 03 Aug 2004 09:12 GMT
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

> Dear all,
>
[quoted text clipped - 31 lines]
> Regards,
> James Wong
James Wong - 04 Aug 2004 04:44 GMT
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

> 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
[quoted text clipped - 39 lines]
> hth,
> Sami
Sami Vaaraniemi - 04 Aug 2004 08:21 GMT
> Hi Sami,
>
[quoted text clipped - 3 lines]
> 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
James Wong - 05 Aug 2004 02:10 GMT
Hi Sami,

Thanks again for your additional information!

Regards,
James Wong

> > Hi Sami,
> >
[quoted text clipped - 17 lines]
> Regards,
> Sami
Darwin Abustan[MSFT] - 21 Dec 2004 00:32 GMT
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.aspx?scid=kb;en-us;326791

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

Darwin Abustan
Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.