I am trying to get Swagger to work with ServiceStack. The web server is located behind a Firewall and accessed from the Internet (my.domain.de:80). Requests are then forwarded to the web server on Port 8070.
When visiting the swagger page it is able to access /api/resources and retrieve the List of ServiceMethods, but then fails to retrieve the List of Operations.
When I use fiddler to inspect the result I see that he /api is missing so that swagger tries to get the List of Operations from /resources/ServiceName instead of /api/resources/ServiceName.
The Swagger-UI gives me the following error message:
Unable to read api 'ServiceName' from path http://my.domain.de/resource/ServiceName (server returned Not Found)
SwaggerConfig:
discoveryUrl:"../../api/resources",
ServiceStack Config:
WebHostUrl = "http://my.domain.de"
Update(2)
If I dont set the WebHostUrl the BasePath in the initial response from ServiceStacks resources service contains the portnumber from the webserver basePath=http://my.domain.de:8060/api. But on the Firewall this port is not reachable, nor do we want it to be reachable.
web.config:
<location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
</location>
Update
in the Inital response the basepath is:
basePath=http://my.domain.de
and by my.domain.de I mean a real world url which is just the hostname without port, url-path, querystring or fragment (I acctually checked wikipedia for the correct names ;)
I have found this other question on StackOverflow, but it did not help me.
Swagger with Service Stack not working
How can I get ServiceStack/Resources Service to either add /api for its returned ServiceList?
Colleague of op here.
I spent some time researching this problem and I believe the issue is a bug in ServiceStack's swagger support.
See here:
https://github.com/ServiceStack/ServiceStack/pull/800
Quote:"When set, use webhosturl for base url in swagger and metadata links"
It is implemented correctly for metadata, but not for swagger.
Line 52 in SwaggerResourcesService.cs overrides the baseurl with the WebHostUrl if it is set, but does not combine with the real path as the implementation in metadata does:
https://github.com/sneal/ServiceStack/blob/6b33f5c2417587b5983c611b4bf8a5d42d88d890/src/ServiceStack.Api.Swagger/SwaggerResourcesService.cs
Related
Technologies
I am using angular 2 and web API technologies in my application. I am calling web API service method from angular via $http call.
What I am doing
Actually API method is reading data from data base and doing huge logic to transform the data for UI entity class (lot of codes and loops are there, so i won't post those here).
What is the problem & root cause
The problem is I am getting 502 Bad get way error when I am calling the API method.
I found the problem because of it's a performance issue. it's working fine for me when the data size is low. But if the data size is large, then I am getting this error.
Note : I have checked the data base query. and it's working fine and return the data very fast.
Performance result details
I have used timer to check the response time of API method
Result of response time as follow :
if the data size is low : 00.00:898767 (hh:mm:ss)
if the data size is huge : 00:06:654389 (hh:mm:ss)
What I understood:
If the method response time is more than 2 mins, then only I am getting the bad get way error. otherwise the method executed successfully without any error.
What I tried to fix this error:
I have tried to increase the executionTimeout=9000 in web config. I also tried with different seconds in executionTimeout.
this is my full web config code
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.web>
<authentication mode="Windows"></authentication>
<authorization>
<deny users="?" />
</authorization>
<httpRuntime executionTimeout = "9000" />
</system.web>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true" />
</system.webServer>
</configuration>
but still i am unable to solve this problem. Could you please let me know how can I fix this issue?
I solved this defect by adding requestTimeout="00:10:00" in <aspNetCore/> section
<aspNetCore processPath="%LAUNCHER_PATH%" requestTimeout="00:10:00"
arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="true" />
Thanks for looking.
Background
I have inherited a very old (12 years) .NET website project what uses web form architecture.
This is a very large codebase and, when running on the web server, depends on a very large local resource folder of images. I am working remotely and have been told that the image folder will not be added to the source control; however, I can access it via a network folder (if connected to VPN).
If I hard-code any of the images to use the network path they work fine, but this is obviously not a good solution since there are thousands of images.
Question
Is it possible to intercept any incoming request for an image file and, if the local image folder is not found (i.e. in development on my machine), use the network path URI instead to get the image? If so, what is the correct way to do this?
What I have Tried
I tried intercepting the requests in the Application_BeginRequest method of the global.asax (which I was surprised to find in such an old project) but this does not intercept image requests apparently. My thinking was that I could re-structure the URL there and then comment that code out in production, but this also seems like it wouldn't be a great solution.
Thanks in advance.
If it's WebForms then you can most certainly use a HTTP Handler to achieve this.
public class ImageHandler : IHttpHandler
{
public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest(HttpContext context)
{
// Handle your request here, using
// context.Request and System.IO
// to serve the image from network
}
}
Then, you'll need to register & configure the Handler in Web.Config like so, for IIS6:
<system.web>
<httpHandlers>
<add verb="*" path="*.jpg,*.png" type="Namespace.ImageHandler, AssemblyName" validate="false" />
</httpHandlers>
</system.web>
Or IIS7:
<system.webServer>
<handlers>
<add name="JpgImage" verb="*" path="*.jpg" type="Namespace.ImageHandler, AssemblyName" resourceType="File" />
<add name="PngImage" verb="*" path="*.png" type="Namespace.ImageHandler, AssemblyName" resourceType="File" />
</handlers>
</system.webServer>
I have a basic WebAPI OData application that seems to refuse to route requests to my controller if the parameter has a '.' in it.
For example:
http://localhost.com/vroot/odata/foo('abc') <== routes correctly
http://localhost.com/vroot/odata/foo('a.bc') <== returns a 404 error
I get the same 404 error even if I replace the '.' with a %2E.
http://localhost.com/vroot/odata/foo('a%2Ebc') <== returns a 404 error
Is this a generally understood problem in WebAPI OData?
Any ideas on what might be going on (or possibly how to work around this ?)
Dots in request urls are interpreted differently by IIS, so try adding the following setting in web.config:
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
(From here: http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html )
Some posts related to your issue:
Dots in URL causes 404 with ASP.NET mvc and IIS
I get an error on any OperationContract with POST: 405 method not allowed
GET work just fine. I've tried it on local and remote server with the webserver e.g. localhost/myPostMethod/myParam
I host the service like these :
RouteTable.Routes.Add(
new ServiceRoute(#"Default",
new CustomWebServiceHostFactory(),
typeof(DefaultService)));
(i use the webHttpBinding inside my CustomWebServiceHostFactory)
Can not change any settings inside IIS on my remote server. I think it's not necessary ether. Seems like the problem is somewhere inside my code.
Tried many thinks and i'm a little bit desperate right now. Would be very happy about any suggestions.
Added header... Solved.
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Methods" value="GET, POST" />
</customHeaders>
</httpProtocol>
</system.webServer>
We created our own redirect httpHandler that accepts all requests (verb="*", path="*"):
<system.webServer>
<handlers>
<remove name="Redirect" />
<add name="staticFileHandler" path="*.html" type="System.Web.StaticFileHandler" verb="GET,HEAD" />
<add name="Redirect" path="*" verb="*" type="RedirectModule.RedirectHandler,
RedirectModule, Version=1.0.0.0, Culture= neutral, publicKeyToken=77c8b6b494e19eeb" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
In the http handler we have code that checks the URL and redirects if the browser it is mobile. In this case if the browser is not mobile or we've already redirected we would like to continue with execution of the static files and display their content.
The problem we're having is that because the http handler we are using accepts all requests the StaticFileHandler doesn't process the HTML file and we always get a white screen.
How do we pass execution from the httphandler to a staticFileHandler through code or the web.config.
Appreciate any help.
Orit
A handler should only decide how to process a file extension (either physical or logical), not when. I think you meant to create a module.
See this answer by Jon Galloway and this MSDN article on Handlers and Modules.
edit: Also, check out ASP.NET/Mobile's first How-To. It shows how to accomplish this in both Web Forms and MVC.