I'm trying to add an ADO.NET data service to a vanilla ASP.NET-MVC project. Does anyone know if these technologies are compatible?
When I Ctrl+f5 the solution and visit the service URL all I get when is the very unhelpful "Request Error ... See server logs" page. Does the Development Web server even write any logs and if so where?
I guessed that routing may be the problem so I added:-
routes.IgnoreRoute("{service}.svc/{*pathInfo}");
in an attempt to fix this but that doesn't help.
I would rather not create a separate ASP.NET Web project just to host the data service. Are there other steps to addiing a Data service in an ASP.NET-MVC project that are not common to standard ASP.NET project?
Did you place debugging atribute into service class ?
**[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]**
public class MyDataService : DataService<...>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(IDataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
**config.UseVerboseErrors = true;**
}
Related
Basically I have an exe, that controls a pizzaria, it should be extended to allow users to choose a pizza slice from the web. The application I have, keeps track of what slices are available at the moment, and only show them on the site.
I've made an asp.net web api project and am hosting that inside my application.
(Owin, self hosting asp.net web api;-) My problem is how to configure the IAppBuilder, to go the normal MVC steps looking for my site, when the url, requested didn't go to an api controller.
public class Startup {
public static void Configuration(IAppBuilder app) {
app.UseStaticFiles();
var apiConfig = new HttpConfiguration();
apiConfig.MapHttpAttributeRoutes();
app.UseWebApi(apiConfig);
// THIS IS WHERE I NEED THE app to look through
// my MVC controllers, to get the view..
app.Run(async context => {
await context.Response.WriteAsync(" My First dummy OWIN App");
});
}
}
(I think I just need to figure out how to get the mvc controllers to get the request.. )
Thanks any help will be appreciated, with this, my first asp/web project in 15 years..
I am following a tutorial on asp.net web api and mongodb here and on step 4 it talks about dependency injection and adding it to the start.cs in the ConfigureServices() method, however this doesnt seem to exist anymore. My web api templates startup.cs looks something like this...
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
So my question is where do I inject my DataAccess class to my web api project as a service? Thanks in advance.
As requested here is my api structure
under LGR.API is the auto generated folders and classes created by visual studios and starting a LGR.Datamodel is my custom class with my api stuff. Really new here... not sure if this correct at all. Feel free to critique with best practices as necessary
It looks like you've created an ASP.NET application, and your tutorial is for ASP.NET Core. Recreate your project and pick the "ASP.NET Core Web Application" template.
How do I get OWIN to host a SOAP endpoint (do not care if WCF is or isn't involved, SOAP gives WSDL which makes services easier to consume by certain clients, that's why I want SOAP and REST)
I suspect the answer is: Implement your own middleware that hosts a SOAP endpoint. If that's the answer so be it, but that's a lot of work so I'll probably just end up sticking with WCF and avoiding OWIN if that's the case. I find it hard to believe no one has implemented a SOAP hosting middleware yet...
As a rule we like to do both REST and SOAP endpoints on our services; currently we use IIS and the WCF restful bits to host the SOAP with [ServiceContract]/[OperationContract] attributes, and the rest is defined with [WebInvoke] attributes, with these attributes the services need no reimplementation for the different endpoint types.
We just use the ASP.NET routes to add new ServiceRoutes which add a rest binding to URI/REST with the same service as a soap binding to URI/SOAP.
Now we're looking at doing some new services work and I'd like to move forward to using OWIN so we can implement our new services with hosting agnosticism as some services will be better served by windows service hosting and some better served by IIS service hosting.
All of my fiddling with things and so far I can come up with no way of getting a SOAP endpoint hosted by OWIN. I have the rest handled fine by making my service inherit from ApiController and then using this little snippet of code in the OWIN app's Configuration method:
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
app.UseWebApi(config);
[...]
There is a custom OWIN middleware example on MSDN that shows how to support SOAP requests. It is not a general purpose WCF host but may be enough to expose your existing WCF Services (i.e. [ServiceContract/OperationContract]) within an ASP.NET Core app. The example does not include support for [WebGet/WebInvoke] but may be enough to get you started.
https://blogs.msdn.microsoft.com/dotnet/2016/09/19/custom-asp-net-core-middleware-example/
If your primary goal is simply to begin writing new services using OWIN and you still plan to host them in IIS using Microsoft.Owin.Host.SystemWeb. You could ignore the WCF requests within the OWIN pipeline and allow the IIS ASP.NET pipeline to handle them. This would enable you to write services that are a combination of OWIN middleware and traditional WCF endpoints.
public static class WCFAppBuilderExtensions
{
public static IAppBuilder IgnoreWCFRequests(this IAppBuilder builder)
{
return builder.MapWhen(context => IsWCFRequest(context), appBuilder =>
{
// Do nothing and allow the IIS ASP.NET pipeline to process the request
});
}
private static bool IsWCFRequest(IOwinContext context)
{
// Determine whether the request is to a WCF endpoint
return context.Request.Path.Value.EndsWith(".svc", StringComparison.OrdinalIgnoreCase);
}
}
Then call the IgnoreWCFRequests extension method when configuring your app.
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
WebApiConfig.Register(config);
app
.IgnoreWCFRequests()
.UseWebApi(config)
.Run(context =>
{
return context.Response.WriteAsync("Default Response");
});
}
}
It's not so easy to host a WCF infrastructure over an OWIN one, sure it can be possible, with a bit of work it's clear possible to adapt, or proxy the owing request-response layer to the WCF infrastructure; WCF provides a not so easy but a complete infrastructure to do something like that.
cpowers answer may work for some, but didn't for me because I have other Filesystems setup within Owin, and I couldn't get both behaviors (fallback to other handlers when needed and also go through OWIN pipelines).
This was the configuration which made it work for me:
Use Owin automatic startup (Remove any appSettings named owin:AutomaticAppStartup)
Do not manually add its handlers in your web.config (or Startup will run twice) (Remove OwinHttpHandlerfrom from <handlers> in you web.config)
Add appBuilder.UseStageMarker(PipelineStage.MapHandler) after builder.UseFileServer()
UseFileServer must happen after all pipelines you setup, otherwise the ones setup after it will not work and you'll get 404
Optionally Fork the pipeline like cpower mentioned
If your OWIN pipelines does not register middlewares for the paths where your legacy stuff is you don't even need to fork your pipeline (my case).
I have started learning WCF. I wrote a simple service to query a SQL relation through LINQ.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = aspNetCompatibilityRequirementsMode.Allowed)]
public class Order_WCFService
{
[OperationContract]
public List<Order> getOrders()
{
List<Order> orderList= null;
try
{
orderList= DAL.GetList<Order>();
return orderList;
}
catch (Exception)
{
throw;
}
}
}
This is located in ASP.NET-MVC project.
I have a simple silverlight application. It's in the same solution, but in a different project.
I would like to consume my service by a silverlight application.
I attempt to "Add Service Reference..." and in the left hand column I have a list of all available ASMX and WCF services. When I click on any of the services, it attempts to download service information, but fails after 10-20 seconds: "An error occured (details) while attempting to find services at..."
What am I doing wrong here?
Thank you
I'm 100% certain that services are functional because I can invoke them through AJAX.
Maybe a stupid question but was the service running when you attempted to add the service reference (if you are using the Visual Studio's built-in web server, was it started and the ASP.NET MVC project containing the service running)? Also you may try giving the full address of the WSDL in the Add Service Reference dialog instead of selecting it from a list after verifying that this WSDL is accessible in your browser.
I've hit a wall on this one. I have a WCF library with a respective WCF web service. A sandbox web application attempts to fire one method from this service.
The service, however, will log requests as they are made. The persistence layer here is built with FluentNHibernate. Session management in a web application has been pretty straight forward in the past(ie HttpModules), but in WCF it got a bit tricky for me.
I followed the notes and examples with the IglooCommons library and added the following line to my global.asax(residing in the web service directory).
protected void Application_Start(object sender, EventArgs e)
{
NHibernateFactory.Initialize(new SessionFactory().BuildSessionFactory());
}
BuildSessionFactory returns the following:
public class SessionFactory
{
public SessionFactory() { }
public ISessionFactory BuildSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration
.MsSql2005
.ConnectionString(x =>
x.FromConnectionStringWithKey("myConnection"))
.ShowSql()
.CurrentSessionContext<WebSessionContext>())
.Mappings(m =>
m.FluentMappings
.AddFromAssemblyOf<OneClass>()
.AddFromAssemblyOf<AnotherClass>()
.Conventions.Add(
PrimaryKey.Name.Is(x => x.EntityType.Name + "ID"),
ForeignKey.EndsWith("ID"),
Table.Is(x => Inflector.Net.Inflector.Pluralize(x.EntityType.Name))))
.BuildSessionFactory();
}
}
The service page(*.svc) loads up with its soothing stock blue "to generate classes use this wsdl" page, with no issue.
When the web application that references this attempts to call a service method,
NHibernateContext.Current().Session
is unable to find any live session. After stepping through the application, the app start method in global.asax is being fired, however seems to be dying(this is a guess) prior to any action requiring it.
I realize IglooCommons may be a bit specific as NHibernateContext is a proprietary library, however, WCF with a persistence layer isn't uncommon. Any thoughts on what I've missed or another direction to take are greatly appreciated.
Additional Note:
For the web application using this service, I've created an "interop" library which was based on the wsdl, auto-generated using svcutil. There isn't a web reference between the web app and the web service, just the web app using the auto-gen classes.
Have you enabled the ASP.NET service hosting environment for your WCF service? This requires that you:
Apply the AspNetCompatibilityRequirementsAttribute to your service with an AspNetCompatibilityRequirementsMode of Required.
That you configure the hosting environment in WCF web.config like so:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<!-- rest of config here -->
</system.serviceModel>
More information about WCF Service hosting with ASP.NET is available here in the MSDN documentation.
This resolution in particular was a misunderstanding of the IglooCommons lib. The "NHibernateContext" attribute in the example was used to decorate the interface, when in reality it needed to decorate the implementation. By moving this alone, the sample on the Igloo site was able to function normally.
As a side note, the other solutions provided here were excellent in expanding the little knowledge I have of inner workings with WCF and its interaction with NHibernate.
Your WCF service svc.cs file should look like this:
[NHibernateContext(Rollback.Automatically)]
public class YourWcfService : IYourWcfService