Solved

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

Posted on 2016-09-15
8
115 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
  • 5
  • 3
8 Comments
 
LVL 49

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 49

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
 

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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 49

Accepted Solution

by:
Ryan Chong earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSLT: how to increment number value if attribute present 4 35
website went down 6 40
Link SQL table to Webpage 9 51
Achieve json result 2 65
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.
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

912 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

22 Experts available now in Live!

Get 1:1 Help Now