Bulk Insert using C# with WEB API in Dynamics CRM - asp.net-web-api

We are migrating our C# code from 2011 endpoint to Web API. We have API version 8.0. We have successfully implemented the Insert/Delete/Update operations using Web API but for bulk operations we are not getting how to implement this in C#. We referred https://gist.github.com/prabirshrestha/3929230 for implementations.
Here the code that we wrote:
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "batch");
MultipartContent batchContent = new MultipartContent("batch");
request.Content = batchContent;
batchContent.Add(new HttpMessageContent(new
HttpRequestMessage(HttpMethod.Get, "contacts")));
response = httpClient.SendAsync(request);
response.Wait();
With this code we are getting error like saying:
This operation is not supported for a relative URI.
Please let us know if anybody can help us to implement this.
Also have question, like is bulk operations are part of Web API 8.0 version or there are introduced after this version?

According to this article, the v8 Web API supports batch operations.
It appears that the full URI of the Web API endpoint may be missing from your HTTPRequestMessage. It should be something like this:
[Organization URI]/api/data/v8.2/accounts
This question may also help.

Related

Spring RestTemplate 404 error for large POST request to .NET Core REST api

I am trying to make a Java (Spring) application which invokes a REST api in a .NET Core application. Everything seems to work in the general case, but now that I am making a POST with an XML string which takes up 80 megabytes on my system, the RestTemplate produces a 404 error code saying "Not found". I have tried to remove the POST size limit in both the .NET Core application (by using the DisableRequestSizeLimit attribute in the API controller) and in the Spring configuration (by setting the variable spring.servlet.multipart.max-request-size to 200MB in application.properties). Neither of it seems to work. Is there some way to fix this? I am willing to use an alternative to the RestTemplate, if that would make sense. I am using the exchange method of the RestTemplate object.
Not found is a general error, if the problem would be sending the request, other problem will happens. I highly recommend you to test the rest api with another tool, like Postman or Insomnia. After that works with the tool try with your client application.
Clarification:
spring.servlet.multipart.max-request-size is for api in your Spring application, no for requesting another services.
Due to Milton BO's answer, I made a request in POSTMAN, which gave me a more detailed error response from the ASP.NET Core app. And it told me to change the maximum allowed post size in the web.config (or appplicationhost.config) file for IIS Express. Furthermore, I am now using the Kestrel server instead of IIS Express, so the DisableRequestSizeLimit attribute now works as expected.

Does Clickatell's new API use HTTP response codes like the old API?

I'm in the process of upgrading from integrating using Clickatell's deprecated API (version 1) to the currently support API as described in their api documentation.
In my old integration, I relied on HTTP status codes (described here) to handle different success and failure scenarios but I can't find any equivalent reference on the new documentation.
Have Clickatell changed to using errorCodes and errorDescriptions within the response bodies in place of the HTTP codes of the old API? Do all responses to requests made to the new API have 202 Accepted status codes?

Content Negotiation fails on using EDMBuilder Web Api 2 (ODATA service)

I am currently working on an OData Web API 2 service using EF6 with a code first approach. My controllers all derive from the base ODataController. I have made use of Ninject for DI and Owin.
I am trying to expose OData but for some strange reason on using the EDMBuilder, content negotiation fails even on a browser, giving the HTTP 406 error.
Content negotiation works when I use the ODataConventionModelBuilder, but I cannot use this as I will not be able to use breeze's client side features.
Wondering if anyone has come across such an issue before while using the EDMBuilder.
Looks like this is documented :(. It is there in the Breeze documentation at the following link with a suggested workaround: http://www.breezejs.com/documentation/odata-server

AJAX + OData + Basic Auth for Sharepoint 2010's ListData.svc, JSON-P or JSON + xdr

I am looking for a way to either:
Do a cross domain plain JSON request a-la YUI IO (http://developer.yahoo.com/yui/3/examples/io/io-xdr.html with Basic Authentication)
or alternatively,
Have Sharepoint 2010's ListData.svc support JSON-P (e.g. /_vti_bin/listdata.svc/?$format=json&$callback=loaded) so I can use jQuery.ajax to make a Basic Authenticated request.
Just to clarify, I'm not sure how the Yahoo example above could support basic authentication (jQuery is a simple mattery). Secondly, the error Sharepoint 2010 throws when attempting JSON-P is:
The query parameter '$format' begins with a system-reserved '$' character but is not recognized.
I know we can retro-fit standard WCF Data Services via http://code.msdn.microsoft.com/DataServicesJSONP but I'm not sure about Sharepoint.
As I am sure some can imagine this would be incredibly useful. Does anyone have an idea of how this could work?
In this situation we ended up accessing the OData service via our .cshtml files using System.Net.WebClient. The application was in the same cloud as the Sharepoint server, so the performance was quite acceptable.

Configuring WCF for Web Browser Access

I'm fairly new to WCF but am technically competent.
I am having trouble getting WCF to play nicely. I currently have a WSHttpBinding set up to a service and it is working when using the WCFTestClient supplied with VS2008. What I would like to do is have the service accessible within the browser.
I currently return a JSON response from my service but am unable, as of yet, to access the data via. a URL. I have seen lots of internet tutorials where they seem to be accessing data a bit like this (note the bolded section):
http://localhost/Service.svc/MethodName?param1=value1&param2=value2
If I try and do that I get a 404 - I am guessing it is looking for a literal file but don't know how to fix it.
Any help you can give would be great, thanks!
You can't do that with WSHttpBinding... you need to expose an endpoint using the WebHttpBinding and have your contract correctly specify the right uri template in the [WebGet] attribute. Here are some pointers to get you started:
Rest in WCF
WebHttpBinding example
WebHttpBinding and JSON

Resources