Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Web service to Upload XML string to DB :  gets error

Posted on 2010-09-07
11
Medium Priority
?
757 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:Richard Quadling
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 
LVL 40

Expert Comment

by:Richard Quadling
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:
Richard Quadling earned 2000 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:Richard Quadling
ID: 33649998
Woo Hoo!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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 article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

824 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