Self Hosted REST Microservice using OWIN and ASP.NET Web API 2

Поділитися
Вставка
  • Опубліковано 13 січ 2016
  • This video demonstrates creating a simple Self Hosted REST service using OWIN and WebAPI2.
    I then create a simple web page to retrieve data from the REST service.
    The C# Desktop project requires two NuGet Packages.
    Open the NuGet Package manager and run the following two lines.
    Install-Package Microsoft.AspNet.WebApi.OwinSelfHost
    Install-Package Microsoft.AspNet.WebApi.Cors
    The video also demonstrates the need to EnableCors with the System.Web.Http.HttpConfiguration object to allow cross origin resource sharing.
    Text version of this tutorial at
    seanwasere.com/self-hosted-re...
    I also have a very similar but slightly more advanced project at my GitHub page
    github.com/Sean-Bradley/Seans...

КОМЕНТАРІ • 13

  • @davidcondit388
    @davidcondit388 4 роки тому +1

    Simple yet comprehensive. Thank you!

  • @meidavis4425
    @meidavis4425 6 років тому

    You are the best. I have used your way to create a self hosting API worked perfectly. Thank you so much the the wonderful video.

  • @eduardofernandez2452
    @eduardofernandez2452 7 років тому +1

    Hi, very good video, it would be excellent if you make a totorial of a complete application, it would be much clearer how the structure and connections between the services work, thank you very much in advance, greetings !!

  • @AdityaKumar-gd6fb
    @AdityaKumar-gd6fb 4 роки тому

    when using this 127.0.0.1:8080/api/websites
    Error>
    An error has occurred.
    Type 'SeansOWINRestService.Website' with data contract name 'Website:schemas.datacontract.org/2004/07/SeansOWINRestService' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.
    System.Runtime.Serialization.SerializationException
    at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle) at WriteArrayOfanyTypeToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , CollectionDataContract ) at System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType) at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle originalDeclaredTypeHandle, Type graphType) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver) at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph) at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content) at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Owin.HttpMessageHandlerAdapter.d__27.MoveNext()
    this coming.
    How to resolve this

  • @sankarrao9688
    @sankarrao9688 5 років тому

    If web application is in another server and microservice is another server, then how can web app can call that microservices?

    • @sbcode
      @sbcode  5 років тому

      enable cors on the microservice

  • @chihabahmed5207
    @chihabahmed5207 7 років тому

    Hi
    i dont get the idea of self-hosting
    i know its like you own a car
    so this service runs on your server not someone elses server.
    can you explain to me what is exactly a self hosted services.
    and how do i host the database of that self-hosted services.
    for instance if i want to make a self-hostes services for a mobile app, i have to have a database, where am i going to host that database. because its a slef-hosted.
    thanks a lot

    • @sbcode
      @sbcode  7 років тому

      "Self hosted" in this case means that the console app created in this tutorial, is also it's own web server. It's an all in one neatly compact executable. requires minimal maintenance.

    • @chihabahmed5207
      @chihabahmed5207 7 років тому

      Can i use .net microservices as a backend for andriod app.
      i want to build andriod app with java but i want it to connect to .net
      is that possible

    • @sbcode
      @sbcode  7 років тому

      Chihab Ahmed yes

    • @chihabahmed5207
      @chihabahmed5207 7 років тому

      so what kind of adapter or machanisim that allow me to connect the front end Java app with .net
      or just obtain the connection through the APIs???
      thanks man

    • @sbcode
      @sbcode  7 років тому

      search google for 'consume rest api in android app' for more specific answer. Perhaps one day i'll create a tutorial for it and link it here.

  • @DivKan007
    @DivKan007 5 років тому

    This is not MicroService