I have written a very basic webservice using Servicestack which works fine, but when I browse to the metadata page for this service, something seems to blow up.
A NullReferenceException is being thrown somewhere inside of Servicestack I believe.
I have the latest version pulled from NuGet.
The version is: 3.9.56.
The implementation of the service is simply this:
[Route("/hello/{Id}", "DELETE")]
public class DeleteHello : IReturnVoid
{
public int Id { get; set; }
}
public class TestService : Service
{
public void Delete(DeleteHello request)
{
}
}
The AppHostBase is as simple as possible. It contains no custom configurations at all, and is hosted in the IIS Express version that comes with Visual Studio 2012.
When I go to http://localhost:45864/json/metadata?op=DeleteHello the exception is thrown.
Am I doing something wrong or what is going on?
Related
I have a development version of Acumatica running locally, and a QA version of Acumatica in the cloud.
I wrote c# program integrating with Acumatica through SOAP. I created WSDL file for Acumatica instance running locally at http://localhost/AcumaticaERP. Now I need to make the program to connect with Acumatica production instance in the cloud. soapClient.Login method does not have Acumatica URL as a parameter.
How do I allow users to dynamically chose an instance of Acumatica to use from within my program?
I would first suggest to look into the REST API since generally that's the recommended integration API to use.
Regarding dynamically changing the endpoint (i.e. Acumatica instance), note that the DefaultSoapClient has a number of overloaded constructors.
There is one where you can specify the endpointConfigurationName (see below). This would mean that your URL should be in your web.config/appsettings of the client application as explained in more detail here: https://help-2020r1.acumatica.com/(W(1))/Help?ScreenId=ShowWiki&pageid=37613e5f-7a72-4dec-b5d9-2525951e99cf
public partial class DefaultSoapClient : System.ServiceModel.ClientBase<ConsoleApp2.ServiceReference1.DefaultSoap>, ConsoleApp2.ServiceReference1.DefaultSoap {
public DefaultSoapClient() {
}
public DefaultSoapClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public DefaultSoapClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public DefaultSoapClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public DefaultSoapClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
In case using configuration files will not work for you, you can refer to this example whereby it is done programmatically:
https://asiablog.acumatica.com/2019/01/dynamic-api-endpoint-url.html
I am currently experimenting with ASP.NET Core MVC by creating a simple blog with static views. I've created a custom class that implements the IViewLocationExpander in order to enumerate a directory structure to retrieve razor views
public class FolderEnumerationViewExpander : IViewLocationExpander
{
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context,
IEnumerable<string> viewLocations)
{
var locations = viewLocations.ToList();
foreach (var directory in Directory.EnumerateDirectories("Views/Blog", "*", SearchOption.AllDirectories))
{
locations.Add($"/{directory.Replace("\\","/")}" + "/{0}.cshtml");
}
return locations.AsEnumerable();
}
}
I've configured this class to be used within Startup.cs's ConfigureServices method
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IPostsMetaDataRepositry>(new JsonPostsMetaDataRepository(ConfigurationPath.Combine("posts.json")));
services.Configure<RazorViewEngineOptions>(o => { o.ViewLocationExpanders.Add(new FolderEnumerationViewExpander()); });
services.AddMvc();
}
This seems to work perfectly when I run my application locally using IISExpress however, when I deploy the application to an Azure AppService, only a handful of the directories within ~/Views/Blog are being enumerated when trying to locate views.
I'm fairly certain the issue is one of configuration but I am having a difficult time tracking down what it could be. Any ideas as to why this may be occurring?
I have the full source of this project on GitHub for reference: https://github.com/pstricker/Develothink
I have a Azure Mobile Services project. When running locally everything works fine, the Application_Start() method gets called which in turn calls my WebApiConfig.Register() method.
However, when published to a live Azure Mobile Services server the Application_Start() does not get called along with the WebApiConfig.Register().
In the servers log I have the following entry:
No bootstrapper found -- using default bootstrapper. A bootstrapper can be specified in one of two ways: Either by defining a public, static class with name 'WebApiConfig' having a public parameter-less member called 'Register', or using the 'IBootstrapper' attribute to define a public class with a default constructor.
Why is Azure Mobile Services not picking up my BootStrapping WebApiConfig?
public static class WebApiConfig
{
public static void Register()
{
Trace.TraceInformation("Hello from WebApiConfig Register().");
// Use this class to set configuration options for your mobile service
ConfigOptions options = new ConfigOptions();
// Use this class to set WebAPI configuration options
HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));
// To display errors in the browser during development, uncomment the following
// line. Comment it out again when you deploy your service for production use.
// config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
}
}
public class WebApiApplication : System.Web.HttpApplication
{
public WebApiApplication()
{
Trace.TraceInformation("Hello from WebApiApplication ctor!");
}
protected void Application_Start()
{
Trace.TraceInformation("Hello from Application_Start()");
//RouteConfig.RegisterRoutes(RouteTable.Routes);
WebApiConfig.Register();
var dataContext = new DataContext();
dataContext.Database.Initialize(false);
}
}
Help is much appreciated!
That is bizarre... It really looks like you got it right. After working with .net backend azure mobile service for few weeks, I might suggest just maybe restart the service in portal and republish. I have hit some weird unexplained stuff just like you are and somehow fix like that.
I am doing some stuff in Service Stack self host in windows service. The link gave me some hint. But in the code, what is StarterTemplateAppListenerHost then?
It is a class which extends AppHostHttpListenerBase (Source here) which is used to provide the http listener and application configuration.
public class StarterTemplateAppListenerHost : AppHostHttpListenerBase
{
static readonly IAppSettings AppSettings = new AppSettings();
public StarterTemplateAppListenerHost()
: base(AppSettings.GetString("ServiceName") ?? "StarterTemplate HttpListener", typeof(HelloService).Assembly) { }
public override void Configure(Funq.Container container)
{
container.Register(new TodoRepository());
}
}
This is demonstrated also in the official documentation here.
I just wonder why the link doesn't have OnStart() etc
The example has two different compilation modes. When it's run in debug, it will not run as a service, and solely uses StarterTemplateAppListenerHost.
When it is run in release mode then it will create a service around the instance of StarterTemplateAppListenerHost. The WinService class provides the OnStart and OnStop methods which are expected of Windows Services by extending System.ServiceProcess.ServiceBase.
So to get it running as a Windows Service you will need to include these 3 files:
Program.cs
WinService.cs
StarterTemplateAppListenerHost.cs
I wish to create a service which will be hosted on Server A (eg URL: http://servera:807). But my main application needs to be hosted on Server B (eg URL: http://serverb:801).
I am curious if this is possible or not? The reason my service and main application need to be on different servers are for reasons beyond my control. The current system uses WCF with the same setup and I'd like to move away from this.
In the examples the Service and Client all seem to be hosted in the same location / in the same solution
Below is a potential set up for solutions/projects. It's simplistic and incomplete but I think helps illustrate one possible set up. You would also need to consider how you want to handle Session information and Authentication since the MVC and ServiceStack handle this separately. See CustomAuthenticationMVC
ServerA.sln (ASP.NET Web Application)
ServiceModel project - holds requests objects and dtos (this can be shared between ServerA and ServerB solutions)
ServiceInterface project - has the Service implementations
Global.asx - has Application_Start method to configure ServiceStack
ServerB.sln (MV4 application)
ServiceModel project (shared)
Views
Models
Controllers
Example of classes in ServiceModel Project:
[Route("/Foos")]
public class Foos : IReturn<FoosResponse>
{}
public class FoosResponse
{
public FoosResponse()
{
this.ResponseStatus = new ResponseStatus();
}
public ResponseStatus ResponseStatus {get; set;}
}
Examples of classes in ServiceInterface project
public class FoosService : Service
{
public FoosResponse Get(Foos request)
{
return new FoosReponse();
}
}
Example how to call ServiceStack API within MVC4 application
public class FoosController
{
public ActionResult Index()
{
var client = new JsonServiceClient("http://servera:807");
var response = client.Get(new Foos());
return View(response);
}
}