Solved

Web service to Upload XML string to DB :  gets error

Posted on 2010-09-07
11
738 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
ID: 33624859
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
ID: 33625787
Line 77, character 40 would be were I would start.

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

Author Comment

by:gautam_reddyc
ID: 33627821
the special characters are # and &..
0
 

Author Comment

by:gautam_reddyc
ID: 33627870
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
ID: 33627938
replace xml special chars (like < by &amp;gt;)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 40

Expert Comment

by:RQuadling
ID: 33628115
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
ID: 33628168
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
ID: 33628186
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
ID: 33628655
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
ID: 33649928
Works like a charm.. thanks..buddy
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33649998
Woo Hoo!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# replace string in void with dR["myData"].ToString() 3 39
C# application error "Parameter Is Not Valid". 3 79
Class object 2 26
Angular - break the dataset in chunks? 7 39
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

17 Experts available now in Live!

Get 1:1 Help Now