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

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.

Related

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

OSB - Split-Join calling secured web service

I create a new Split-Join (in the OSB workshop application). Then
I use an action "Invoke Service" to call a not secured business service. So far no problem. When I assign a security policy to my business service, the OSB does not accept. Here is the error message in the OSB workshop:
[Parallel, Scope, Invoke Service]
The WSDL Binding for BusinessService "OSB/1_0/BusinessServices/TestBS" is not supported: The service feature "WS-Security" is not supported.
How can I call a secured business service in a splitJoin?
Thanks
I'll put a little more expanded version of the correct answer of user2364825.
Split-Join is actually a "window" into an older product (that's why it looks and behave differently from OSB). That product has some limitation, including inability to work with WS_POLICY.
There are two commonly used workarounds for that.
Approach #1. Make a version of the same WSDL stripped of WS_POLICY and use it in the Split-Join. From the Split-Join, call the intermediate proxy with that stripped WSDL which in turn calls a business service with the original WSDL.
BizService(Stripped WSDL)->Split-Join->Proxy2(Stripped WSDL)->BizService(Real WSDL)
That approach only works if the WS_POLICY headers are created by OSB code.
If the message going via Split-Join already has some SOAP Headers (including Policies), those are going to be lost, and the approach #1 is not working.
Approach #2. Make a custom WSDL which wraps the original message with all its SOAP Headers and whatnot. Use that WSDL for Split-Join, pass the wrapped message to an unwrapping proxy, and then call the real proxy/biz.
BizService(Wrapper WSDL)->Split-Join->Proxy2(Wrapper WSDL)->BizService(Real WSDL)
The second approach is more complex, but also more powerful. For instance, it easily can be extended to support user headers (Split-Join doesn't support them too), passing debug information and pretty much anything else.
This approach is implemented in my GenericParallel service which does all above and some more.
I also have a blog post outlining passing the SOAP Headers via Split-Join in a bit more details. (The WS_Policy is just a SOAP Header after all).
YOu can never a call a WSDL based proxy/Business Service that has WS_POLICY defined in the WSDL. You need to have a intermediate business/proxy to pass the message to the WS-policy containg WSDL service.

Backbone Collection.fetch() when after session timeout

I have an ASP.NET MVC4 sub web application added in to an existing ASP.NET WebForm web site. the whole website is using forms authentication.
In my MVC4 client side, I use Backbone.js for building the application, and the client application is most likely a SPA.
Everything works fine, but after session timeout my application does not redirect to log-in page.
I tried the error callback on Collection.fetch method, it was triggered (which is good) when trying to fetch after session time out.
However, the response status code is 200 (OK) with response content is the log-in page content.
So, my question is, in error handler how do I know whether the callback is triggered by session timeout or any other unexpected error?
If determined, how should I do to let Backbone redirect page to log-in page while referring current page?
Here is something what Phil Haack had blogged about
Exceprts from the post :
Possible Solutions
I’m going to cover a few possible solutions I’ve seen around the web and then present the one that I prefer. It’s not that these other solutions are wrong, but they are only correct in some cases.
Remove Forms Authentication
If you don’t need FormsAuth, one simple solution is to remove the forms authentication module as this post suggests. This is a great solution if you’re sole purpose is to use ASP.NET to host a Web API service and you don’t need forms authentication. But it’s not a great solution if your app is both a web application and a web service.
Register an HttpModule to convert Redirects to 401
This blog post suggests registering an HTTP Module that converts any 302 request to a 401. There are two problems with this approach. The first is that it breaks the case where the redirect is legitimate and not the result of FormsAuth. The second is that it requires manual configuration of an HttpModule.
Install-Package MembershipService.Mvc
My colleague, Steve Sanderson, has an even better approach with his MembershipService.Mvc and MembershipService.WebForms NuGet packages. These packages expose ASP.NET Membership as a service that you can call from multiple devices.
Some more info from comment of this blog
We had the same problem. But what we did, was to hook to AuthenticateRequest (just like you did) and we also checked the request to see if it's ajax or not (again, just like what you did). But at this point, we simply returned a JSON like {location: 'http://www.domain.com/path-to-login-page'} and we simply ended response in that method with HTTP code 200. This way, jQuery still gets a JSON result. But if the result has a "location" property, we simply do a client-side redirect to login page. That's our way and it works like a charm.

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

How to call Java web service (JAX-WS) from AJAX?

I am developing java web services (JAX-WS) to insert data into mysql DB and retrieve it. This web service has two methods i.e. fetchFromDB and insertIntoDB. Services seems to be running fine when I test them using netbeans IDE.
Address: /CalculatorWSService
WSDL: /CalculatorWSService?wsdl
but when I try to access it using AJAX's xmlHttpRequest object by providing url http://localhost:8080/CalculatorApp/CalculatorWSService. It is not able to access it. I have developed C# web services and It has been so easy to access them with a url but java web services don't seem to follow that.
My question is
What url to use to access the web service operations in AJAX? (Do I need to use '?wsdl' in the url?
Is there a javascript ajax library to easily access JAX-WS web services?
Apache Axis web services are a better choice over JAX-WS?
Please help me, Thanks, Jay
I was having the same problem of yours, couldn't invoke a Jax-ws web service from Javascript, but i've found a way to do this.
The Url to use can be your same (EndPointAddress) "http://localhost:8080/CalculatorApp/CalculatorWSService"
but when you create the XMLHttpRequest object from javascript you have to:
* Use the POST method to open the URL , i tried with GET but it didn't work for me.
* Set the SOAPAction Request Header to the one in your wsdl, even if its empty "".
* Be very careful with the request body to send, the soap Envelope must be correct.
hope this can help you!.
Bye.
Paul Manjarres.
From the client's perspective, I wasn't expecting significant differences between Axis and JAX-WS. Everything the client needs should be in the WSDL.
One thing that sometimes happens is that the URL used when developing a WebService references the develpoment host and port (and maybe even the ContextRoot) When deployed to a particular server any of those could be changed. Ideally a new WSDL could be created with new "binding" information.
My first step would be to point a browser directly at the Web Service you want to invoke. In my environments that returns a nice "Hi this is a Web Service" kind of message. If you get 401 not found errors then you just need to study exactly how the web service was deployed. Was a different port or context root specified?

Resources