Solved

Web service to Upload XML string to DB :  gets error

Posted on 2010-09-07
11
732 Views
Last Modified: 2012-06-21
I have a web service that accepts the xml string and uploads to the database..

  [WebMethod]
        public void Service(string XML)
        {
            try
            {
                using (DBDataContext db = new DBDataContext())
                {
                    db.ImportXML(XElement.Parse(XML));
                }

               
            }
            catch (Exception err)
            {
               
                throw err;
            }
        }

iam getting the below error
HTTP Transport error javax.xml.soap.SOAPException Error parsing envelope: (77,40) Invalid char in Text.

i know it is occurning beceause of some invalid characters in the xml string..
is there any other way to do it.. can anyone help.

also what do i need to do if i need to upload 100mb data..
0
Comment
Question by:gautam_reddyc
  • 5
  • 4
  • 2
11 Comments
 
LVL 24

Expert Comment

by:alexey_gusev
Comment Utility
first of all, you should detect what character is invalid.

in general, you might want to encode your xml string before sending it to ws
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Line 77, character 40 would be were I would start.

At a guess, you have a < or a >.
0
 

Author Comment

by:gautam_reddyc
Comment Utility
the special characters are # and &..
0
 

Author Comment

by:gautam_reddyc
Comment Utility
we are on the web service side.. we have no control of what is being sent as input.. how do we parse it
0
 
LVL 24

Expert Comment

by:alexey_gusev
Comment Utility
replace xml special chars (like < by &amp;gt;)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
If it is a real soap service, then you reject it. It isn't valid XML and that's a requirement.

Can you show the node with the bad chars?

# doesn't ring any bells as far as I know.

& => &amp;

Unless you have something like ...

&#123; and you want that as the 6 characters, rather than { it represents.

In that case ...

&amp;#123; should be used.

Again, it isn't your concern normally as this is bad data.

0
 

Author Comment

by:gautam_reddyc
Comment Utility
it is in the comments tag
 <COMMENT>Item #1089 building </COMMENT>.. there are bunch of comments tag..
how to replace all.. any idea?
0
 

Author Comment

by:gautam_reddyc
Comment Utility
i know this is a bad data.. but we need to parse the entire xml string. identify all the special characters and replace them with good data..
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 500 total points
Comment Utility
Not being rude, but good luck.

What criteria makes "bad data"?

That's why we have a parser to do this for us. It is inordinately complicated.

In essence you need to parse every character to determine if it < is for / or just some orphaned < in the middle of nowhere.

#1089 really shouldn't be an issue.

<?xml version="1.0"?>
#1089

is perfectly valid.

But ...

Assuming you CAN get hold of the XML before it gets to the parser ...

Using the regex ...

>(?![\r\n]++)([^<]*?)(?![\r\n]++)<(?![\r\n]++)([^<]*?)(?![\r\n]++)<

could work.


Dim ResultString As String
Try
	ResultString = Regex.Replace(XMLString, ">(?![\r\n]+)([^<]*?)(?![\r\n]+)<(?![\r\n]+)([^<]*?)(?![\r\n]+)<", ">$1&lt;$2<", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
Catch ex As ArgumentException
	'Syntax error in the regular expression
End Try

Open in new window

0
 

Author Closing Comment

by:gautam_reddyc
Comment Utility
Works like a charm.. thanks..buddy
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Woo Hoo!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now