Getting the schema in swashbuck when using HttpResponseMessage, in WebApi - asp.net-web-api

I'm attempting to use Swashbuckle to generate a swagger inteface for our API, we're returning HttpResponseMessage in our controller methods.
The docs indicate to use the [ResponseType(…)] attribute to indicate the actual return type. But that attribute is restricted to .net 4.5 (I believe, will gladly be proven wrong), and won't work in a .net4 project.
There are the XML comments, however I couldn't see how to use them the generate the schema information (I've taken a look through the unit tests in the project, but couldn't figure out if it's supported)

Related

I am looking for Fhir Resource validation against Fhir Structure definition

I am looking for Fhir Resource validation against Fhir Structure definition using .net core
I found there is a lib org.hl7.fhir.validator.jar and I couldn't find a better way to do validation through c# code, my requirements are simple
Cardinality validation
Values
Bindings
Profiles
I have an idea in my mind, which is passing the FhirResource as a parameter and load the structure definition file and check the properties and return the error messages as Operational Outcome. Can someone advise me a best way to try it in C# specially in .NET core?
You can use the validation functionality of the .NET FHIR API (https://www.nuget.org/packages/Hl7.Fhir.STU3/), see here (https://github.com/FirelyTeam/Furore.Fhir.ValidationDemo) for a demo application that uses this library.
Although the demo is a winforms project, the .NET FHIR API is fully .NET Core compatible.

Why is a SoapActionCallBack sometimes necessairy?

I'm working on a webservice client using Spring-WS. It's not my first webservice project, using Spring-WS. But I am new in this particular project.
We generate dao-objects by using the maven-jaxb2-plugin.
I'm using Spring-WS WebServiceTemplate, with a standard marshaller and unmarshaller set.
In a previous project, I could just do my webservice calls using:
webserviceTemplate.marshallSendAndReceive(new ObjectFactory().createSomeRequest());
In my current project, I need to provide a SoapActionCallback, provided with the SoapActionUrl.
webserviceTemplate.marshallSendAndReceive(new ObjectFactory().createSomeRequest, new SoapActionCallback("http://some-action-url.com/action"));
If I do not provide this SoapActionUrl, I don't get a result, and when debugging, I see a surpressed exception:
Couldn't get a SAX parser while constructing a envelope
I'd like to remove those SoapActionUrls. Using the correct generated objects by maven-jaxb2-plugin, should automatically refer to the correct actionurl?
I've googled this, but did not find too much info about it.
I'd like to know why I just could 'leave the SoapActionCallback' in the first case, and in the second case, I'm obligated to provide this.
I'm not aware of specific technology used on the server-side, as the webservices are developed by an external partner.
Can someone explain this?

Queryable Web API 2 OData serialization

I have a lighweight setup where I am using Web API 2 with OData but do not create an "/odata" endpoint with its accompanying "/odata/$metadata" but instead just use standard ApiController's with attribute routing and Get methods marked with an override of [Queryable]: [InlineCountQueryable] detailed here Web API, OData, $inlinecount and testing.
It all works very well except that I can only expose dedicated model classes without any collections or object properties because the JSON serializer serializes the whole object graph. My ideal behavior would be to just have all collections ignored completely and object properties only included on $expand.
I believe this can be made to work because an OData Web Api 2 scaffold VS 2013 creates over an entity framework context has similar behavior, but I would like to keep this as lean as possible and avoid going that route as I found it to be a bit brittle and this service does not need to expose a $metadata description.
Update
I did some digging in the aspnet samples and found the "CustomODataFormatter" sample which seems to expose the machinery I would need to modify.. however the ODataSerializerProvider/ODataSerializer setup outlined there does not work with with attribute routing at all (any method defined with [Route("Some/Url")]).
Given that this seems to be what I need, does anyone know if attribute routing and the odata serializer provider mechanism should work together?
[JsonIgnore] or [DataMember] can be used to ignore properties for json.net serializer. webapi.odata 5.2 supports ODataRouteAttribute, an example is here.

OData without IQueryable

I’m thinking of using OData for my web service (based on Web API). Unfortunately, my datasource is NOT IQueryable. Instead of implementing my own IQueryable I pretty much followed this blog post.
What I don’t understand is how to get to my entity data model (EDM)? Do I have to model an EDM for example in the Designer? Or is this for EF only and I can use „plain“ classes instead and set relation-attributes? I don’t want to expose my internal data structures therefore my EDM is more like DTOs...
In an example I’ve seen that I‘m supposed to derive from EntitySetController in order to get the OData-compliant HTTP response. I believe I can’t use EntitySetController as I don’t support IQueryable. What am I supposed to do in order to get a proper response anyway?
You can build an EDM model yourself. You can use the ODataConventionModelBuilder class to build your EDM model. This tutorial has some sample code.
Also, checkout the samples on OData from here, especially the ODataServiceSample and ODataCompositeKeySample. They should get you started.
Also, if you do not have an IQueryable, you could derive from ODataController instead of EntitySetController.

How to configure OData not handle non-odata exceptions in Web Api

I want to use OData in Web Api for few Action methods in a Controller. What is happening is that once i enable OData in Web Api, the error message format is getting changes for all error .
Is there any way to configure Odata only for specific controller/action routes.
Error Message before Enabling OData looks like:
{"Message":"User Name/Password are invalid ."}
Error Message after Enabling OData looks like:
{
"odata.error":{
"message":{
"lang":"en-US","value":"User Name/Password are invalid ."
}
}
}
I would like to configure OData to handle only specific controllers so that rest of the APIs have no impact of OData setting. Your help is appreciated.
One of the big changes we made between RC and RTM is that we've completely removed the EnableOData extension method. We realized that registering OData formatters globally was a bad idea because it impacts controllers regardless of whether they're meant to be OData controllers.
So, in our v1 release for OData and in our current nightly builds, we've added a new base class called ODataController. If you derive from ODataController (or EntitySetController), you will automatically get support for OData just for that controller. It shouldn't affect the rest of your controllers the way it does now. You should also use config.Routes.MapODataRoute instead of EnableOData.
You can install our latest nightly build using these instructions:
http://blogs.msdn.com/b/henrikn/archive/2012/06/01/using-nightly-asp-net-web-stack-nuget-packages-with-vs-2012-rc.aspx
It should be pretty stable at this point.

Resources