Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Data at the root level is invalid. Line 1, position 1

Posted on 2016-09-15
8
Medium Priority
?
889 Views
Last Modified: 2016-09-16
I hope I can explain this fully :)

I have a web service URL that accepts a JSON string from a 3rd party application but it is failing with the above error.

Two things to note:
1. if I configure the 3rd party app to send to a public testing URL (http://requestb.in) it seems to work just fine
2. If I copy the raw body and test it directly on my server, it also works perfectly and return a 200 response

However, when I configure the 3rd party app to send to my URL my service returns 500 response. I have added the application/json mime type to IIS.

I'm sure the issue is on my end but I'm at a loss as to how to troubleshoot this further

The attached image shows the test screen and the resulting 200 response
testing.png
Any help would be greatly appreciated
0
Comment
Question by:BrianFord
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41799694
at your web service, did it provide a sample on how the request parameters should look like?

also, what's your 3rd party app? is it in .net, java, php, etc?
0
 

Author Comment

by:BrianFord
ID: 41799718
The 3rd party app is HubSpot (hubspot.com) I have no control over what/how they send the data but I'm certain their POST is correct, it's something my end.

It's just a string parameter, however I'm not sure I should be using a parameter as the data is sent in the RAW BODY?
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41799825
>>Data at the root level is invalid. Line 1, position 1
I'm actually facing similar issue recently but I was managed to fix the issue by applying similar fixes in this link:

Data at the root level is invalid. Line 1, position 1.
http://www.ipreferjim.com/2014/09/data-at-the-root-level-is-invalid-line-1-position-1/

you can also get some explanation from this article:

Data at the root level is invalid
http://madskristensen.net/post/data-at-the-root-level-is-invalid

both required fixes in coding.

for your case, perhaps you could advise the support from HubSpot (hubspot.com) and see if they can provide you some solutions to solve your issue.

I'm thinking the issue relying on the approach we send the request to your web service.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:BrianFord
ID: 41799869
I think what I need to do here is get the RAW BODY from the request and not a parameter, I've seen several posts using the <FromBody> method but my code doesn't recognize teh keyword for some reason
0
 

Author Comment

by:BrianFord
ID: 41800404
I've looked at both of those and they don't really answer my question as they are both talking about XML documents and my issue is with a JSON format string.

my web service is just about as simple as it gets, it does no processing and simply return a 200.

But when I POST the JSON string to it I get the Data at the root level is invalid error

This is the web method (HttpPost)


Imports System.Web.Services
Imports System.Web.Http

<System.Web.Script.Services.ScriptService()>
<WebService(Namespace:="http://XXXXXXXXX.com/")>
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Public Class HubSpot
    Inherits System.Web.Services.WebService

    <HttpPost()>
    Public Function ConvertMarketingQualifiedToLead(<FromBody> ByVal pJSON As String) As Integer

        Return 200

    End Function

End Class

Open in new window


Can't get much simpler than that :(
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 41800848
can this web service be accessible publicly?

on a separate note, are you able to use test tool such as "Postman"?

https://www.getpostman.com/

you can try to test your web service there, and if the posting is succeeded, can you show me what is inside the dialog after clicking the "Generate Code"?
SnapShot.png
and see if you could get a status 200 as the response status?
0
 

Author Comment

by:BrianFord
ID: 41801278
Ryan,

I tested using postman and still got a 500 error :(

Here's what I used: unfortunately I can'd display the host info :)

POST /HubSpot.asmx HTTP/1.1
Host: xxxxxxx.com
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 190b3c0e-7603-cb90-d567-961cb0b98fb9

{
  "status": "error",
  "message": "contact does not exist",
  "correlationId": "7d60e72c-98f4-4ca4-916e-89a792d7266e",
  "requestId": "30770fba-1ded-4d9f-8d2e-0277564729e1"
}

And here is the result:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()
   at System.Xml.XmlReader.MoveToContent()
   at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent()
   at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()
   at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()
   at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)
   at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
   at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
   --- End of inner exception stack trace ---</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>
0
 

Author Closing Comment

by:BrianFord
ID: 41802150
Thanks for trying Ryan,

I have rebuilt the app using WebAPI & controllers etc. and everything is now working perfectly
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 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