HTTP Error 500.0 - Internal Server Error in Secure WCF Service - asp.net

Getting following error after hosting WCF Service in IIS.
HTTP Error 500.0 - Internal Server Error. The page cannot be displayed
because an internal server error has occurred.
Module IsapiModule
Notification ExecuteRequestHandler
Handler svc-ISAPI-4.0_32bit
Error Code 0x00000000
It is HTTPS having a secure certificate WCF Service.
Please help me to solve this problem.

It can be caused by many different things. You should try the following solutions:
1 First way
Right click the folder where your site is located: "C:\Users\NAME\SiteName" and select Properties.
Select the Security tab and click on Edit.
Add.. and type in "IIS_IUSRS".
2 Second way
By default, WCF Service OperationContracts can only be invoked using an HTTP POST. When you call open() on the Titanium HTTPClient, are you specifying a GET or POST for HTTP method parameter?
Secondly, since your service binding is using SOAP 1.1, you need to pass a SOAPAction header in your request so that WCF can route the message to the GetData method. If an Action parameter is not specified in the service's OperationContract attribute, the Action should be the method name preceded by the namespace and service contract name (probably http://tempuri.org/IService1/GetData if you're using what the default WCF application created). You'll also need to specify a content-type. So, you'd need to setup your xhr like this prior to calling send:
xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-16');
xhr.setRequestHeader('SOAPAction',
'"http://tempuri.org/IService1/GetData"'); xhr.send(s); Also, you can
explicitly specify an action for a WCF service operation:
[OperationContract(Action = "MyAction")] string GetData() {
// ...snip... }
xhr.setRequestHeader('SOAPAction', '"MyAction"');
And lastly, you can allow service operations to be invoked via an HTTP GET by decorating the method with the [WebGet] attribute. This allows the operation to be called in REST fashion: http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.aspx

Related

Is there a way to intercept RPC calls to UNIMPLEMENTED RPC

I made a change to the .proto file where the path of a method changed
old .proto
package foo
rpc test
Method path is foo.test
new .proto
package foo.v1
rpc test
Method path is foo.v1.test
Of course, old clients will stop working with error
12 UNIMPLEMENTED: unknown service foo.test
I don't want to version my APIs instead I want to run a server interceptor that fixes the path for each incoming request.
The issue is the client gets an error response UNIMPLEMENTED before the request is handled by the interceptor.
To my understanding, the interceptor function is executed before the handler but, it seems there is code running that check the connection and the method name before the interceptor.
My question is how to get the server interceptor to run first and change the method path?
Ps. the cleint uses grpc-js
The method path can't be changed after call method. The interceptor execute later than find method by service and method name. So you should not remove the origin method when any client still call this method.

Handle invalid requests errors in .net core 2.1 web api

What I have:
A simple Web API - POST api/examples
Postman to send the request.
When I make the request with the content type set as application/json everything works just fine. But when I change to anything else I get the following response:
{
"": [
"The input was not valid."
]
}
From Kestrel logs I get:
the application completed without reading the entire request body.
This is how the web api is handling invalid requests. What I want to find out is how can I capture and handle this kind of exception and change the default message.
I do have a error handling middleware, but in this scenario the request is invalid, so it's never called.
How can I change this default behavior?
Well, after some while, I had to come back to this issue.
I've find out that this validation has to do with the automatic model state validation of the ASP.NET Core Framework. So everytime a invalid value is passed to the web API controller, a filter, the ModelStateInvalidFilter, is executed prior and ends up firing the 400 bad request: "The input was not valid."
Although there are some ways to override this behavior, for my case, I found it best to just disable it. To do so just add the following lines to your Startup.cs in the ConfigureServices method:
services.Configure<ApiBehaviorOptions>(options =>
{
options.SuppressModelStateInvalidFilter = true;
});
More details about this and how to override it, you can check here:
http://www.talkingdotnet.com/disable-automatic-model-state-validation-in-asp-net-core-2-1/
and here:
Correct way to disable model validation in ASP.Net Core 2 MVC

Spring Security OAuth2 Behind a Proxy Server

There seem to be many examples of Spring Security OAuth2, but most of them run on localhost at some specific set of ports. I was able to get my application working with ports specified for my AuthorizationServer and my ResourceServer. The next step I needed to take was move this application behind a proxy server, but the application stopped functioning. The main issues seem to be path related, but I'm struggling with lack of examples on how to accomplish the task of moving OAuth2 Spring behind a proxy server. I've focused on overriding the WhitelabelApprovalEndpoint, but I'm not sure if this is what is required.
I was able to create a controller that is nearly identical to the WhiteLabelApprovalEndpoint, but do not know how to adapt it to accommodate being behind a proxy.
#Controller
#SessionAttributes("authorizationRequest")
public class ApprovalEndpoint {
#RequestMapping("/oauth/confirm_access")
...
private static String TEMPLATE = "<html><body><h1>OAuth Approval</h1>"
+ "<p>Do you authorize '${authorizationRequest.clientId}' to access your protected resources?</p>"
+ "<form id='confirmationForm' name='confirmationForm' action='authorize' method='post'><input name='user_oauth_approval' value='true' type='hidden'/>%csrf%%scopes%<label><input name='authorize' value='Authorize' type='submit'/></label></form>"
+ "%denial%</body></html>";
...
The only change I made to the class was to update the form action string, making the path relative by replacing
action='${path}/oauth/authorize'
with
action='authorize'
This allows the POST to go to the correct URL
http://localhost/proxy/stuff/javaPath/oauth/authorize
instead of
http://javaPath/oauth/authorize
The latter doesn't map when submitted through Apache (the frontend proxy). But it would seem that this creates other problems in the Java application, because this results in the error
error="invalid_request", error_description="Cannot approve uninitialized authorization request."
I see that this exception is thrown in the AuthorizationEndpoint when the authorizationRequest is null. This looks like it should be handled by my custom class having SessionAttributes set properly, but updating the just the path that I'm POSTing to seems to break this.
May be you already solved it but posting the answer as it may help someone.
It is because authorize end point URL (domain + path(including proxy)) should be consistent. I mean either it should be 'localhost' or your proxy path but it should be consistent.
As OAuth uses session internally and later fetches it from the same path (when the POST happens) . So if the URL changes (POST) it wont get the session then it throws Cannot approve uninitialized authorization request.
For my case ,I was using the authorize end point as:
https://mydomain/myapp/oauth/authorize?grant_type=authorization_code&client_id=clientid&redirect_uri=http://localhost:8181&response_type=code
but in the properties I was having :
server:
session:
cookie:
path: /appProxy
context-path: /myapp
port: 8081
After successful authorization when POST is done on it tries to fetch the session from /appProxy/myapp instead of /myapp and resulting in Cannot approve uninitialized authorization request.
So to solve this, I can either remove Session.cookie.path property or run Oauth server on https://mydomain/appProxy/myapp/oauth/authorize to make it consistent.

Is there a component in camel for a service built on Spring RestTemplate?

I have a REST Service running in Tomcat server. I created this REST Service using Spring RESTTemplate. So is there a component in CAMEL to use this exposed Web service?
i have used http component. i am aware that we cannot use http component to expose a service. So please let me know which component to use.Here is a detailed description of the problem.
Service created in rest Template runs in a server which you can see in from part of camel code
i use camel to expose this service to another http service and the response of this service is the response from the other service.
so my camel code looks like this:
from("http://localhost:8080/rest/emp/dummy").to(http://anotherweservice.com")
I get this error.
Failed to create route route1: Route(route1)[[From[]] -> [process[com.routes..... because of uri must be specified and not empty
Have a look at http://camel.apache.org/how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html.
Using the Jetty component, this looks as follows:
from("jetty:http://0.0.0.0:8080/myapp?matchOnUriPrefix=true")
.log("myapp: httpPath = ${header.CamelHttpPath}")
.to("jetty:http://localhost:8082/remoteapp?bridgeEndpoint=true&throwExceptionOnFailure=false")
In this example, the request is forwarded to another Jetty Camel endpoint:
from("jetty:http://0.0.0.0:8082/remoteapp?matchOnUriPrefix=true")
.log("remoteapp: httpPath = ${header.CamelHttpPath}")
.setBody(simple("${header.CamelHttpPath}"));
The HTTP path /hello/world is transfered to the endpoint, as can be seen when the service is invoked with http://localhost:8080/myapp/hello/world. In this case the body /hello/world is returned. And in the log it says:
INFO myapp: httpPath = /hello/world
INFO remoteapp: httpPath = /hello/world

Access wrapped request web method from web service in asp.net

I have a web service method taking multiple parameters.
Therefor the BodyStyle = WebMessageBodyStyle.Wrapped is set.
I want to access this method from a web service client therefor I did add the url of the service method to Reference->Add Services and I get the following error.
"There was an error downloading 'http://localhost:8080/Api/StoreI'.
The request failed with HTTP status 405: Method Not Allowed.
Metadata contains a reference that cannot be resolved: 'http://localhost:8080/Api/StoreI'.
The content type application/json of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8).
If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.
The first 323 bytes of the response were: '{"ErrorCode":110,"ErrorDetails":null,"Message":"The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'.
This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details."}'.
The remote server returned an error: (500) Internal Server Error.
If the service is defined in the current solution, try building the solution and adding the service reference again."
What should I do in order to resolve this error?
What are the steps to access a secure web service from a client?
I an new to web services.
A reply would be highly appreciated.
Thanks.
I am not expert but change
BodyStyle = WebMessageBodyStyle.Wrapped
to
BodyStyle = WebMessageBodyStyle.Bare
The usage of the wrapped on the operation description does not add a layer of security on the message body. It simply wraps the request (or the response) in an XML element

Resources