Domanda

I have been struggling with this for the last day or so and need some help.

I have been developing a MVC web API project in visual studio which will be used as a back-end to a SharePoint powered front-end.

I am having issues consuming the data exposed through the API in SharePoint 2010.

I have tried adding the data as an External Content Type, but I cannot find anything useful in setting one up that will allow me to get data from a web API.

I have also tried adding it as a REST service but when I try and add a data view in SharePoint designer, the following error is returned:

The server returned a non-specific error when trying to get data from the data source. Check the format and content of your query and try again.

I have temporarily turned off all firewalls on the SharePoint server and local machine the API is running from but the error is still returned. Also, the API correctly returns data to a web browser on the share point server.

I have tried both XML and JSON, both throw the above error.

Does anyone have any good sources which explain what i am trying to do in SharePoint, or have any hints as to what the error might be and possible solutions?

Thanks,

Dale

È stato utile?

Soluzione

Ok, I finally figured this out. After many many hours of head banging.

It seems that the ASP.NET MVC framework returns JSON as default it if cannot find a content-type or Accept header.

As SharePoint does not allow you to customise the headers for data sources, it was receiving JSON back as a default.

I Couldn't find a way to override this, so i had to remove the JSON formatter from my ASP.NET API as a temporary solution.

GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.JsonFormatter);

Now, it returns XML regardless of the content disposition.

Edit:

I switched the formatters around, so if the Accept/Content-type is unknown, it defaults to XML.

var switch_it = GlobalConfiguration.Configuration.Formatters.JsonFormatter; GlobalConfiguration.Configuration.Formatters[0] = GlobalConfiguration.Configuration.Formatters[1]; GlobalConfiguration.Configuration.Formatters[1] = switch_it;

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top