Hello preport,
From your description, I understand you have an ASP.NET webservice which
transfer some data(retrieved from database) from server to client. However,
it currently report exception when the response data contains some invalid
characters, correct?
Based on my experience, the problem you suffer here is likely due to you
directly expose large blob data(binary or text) through webservice's
paramter or return value. Since webservice request/response data is
encapsulated in XML based SOAP message, if there contains some invalid
byte/chars (such as '<', '>', '&' ...) in the message data, it will cause
error.
For your scenario, I'd like to confirm the following things first:
** how did you define your custom class which contains the database data
** have you already manually encode the data being transfered in
webservice's code?
If convenient you can post some code snippet here so that I can get a clear
view. Also, marking the class as "Serializable" does not help here because
webservice will serialize the class objects through XMLSerialization while
the "Serializable" attribute is used for binary seriailzation.
For this scenario, generally there are two approaches here:
1. In our webservice's code, we can manually use some string or binary
encoding methods to encode the data we would transfer in our custom class's
property, and at client-side, we can decode it. For example, we can use
Convert.ToBase64String to convert binary data into base64 string which is
safe to transfer in webservice. We can also use HttpUtility.HtmlEncode to
make the string/text data safe to be transfer(those particular chars will
be escaped...).
Also, if you do want to send large binary data in webservice, you can
consider using the WSE component (latest version 3.0 for .net framework
2.0).
#Web Services Enhancements (WSE) 3.0 for Microsoft .NET
http://www.microsoft.com/downloads/details.aspx?familyid=018a09fd-3a74-43c5- 8ec1-8d789091255d&displaylang=en
2. In .net framework 2.0, it expose the "IXmlSerializable" interface to let
us customize our custom class's XML Serialization process. thus, for your
scenario, you can also consider let your custom class which contains the
database data(contains the invalid chars) and then add the
encoding/escaping code in the IXmlSerialable interface's implementation
methods.
#Customizing XML Serialization in .NET 2.0 Using the IXmlSerializable
Interface
http://www.devx.com/dotnet/Article/29720 #How to: Send and Receive Large Amounts of Data to and from a Web Service
http://msdn.microsoft.com/library/en-us/wse3.0/html/b4b19453-e4e4-4056-906d-
72504ed8c0df.asp?frame=true
Please feel free to let me know if there is anything I missed or if you
have any further questions.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx. ==================================================