Web Core / XData without models?

These are likely completely separate issues, but related. I'm very happily chugging along using XData and Web Core without using any of the ORM / model stuff. Not a criticism of that approach, just that what I've got working I'm pretty happy with. Two questions have come up.

First, on the Swagger page, there is still this little model that is hanging off the bottom... an empty System.JSON.TJSONObject model. Is there anyway to turn off the 'models' section completely?

Second, when my Web Core app is doing its thing, mostly via RawInvokeAsync calls, I see a lot of calls going to the XData server for this same thing - $model. It isn't breaking anything, but does take up server time and resources to respond to them and isn't doing anything of value as near as I can tell, in my situation. I'm sure they are super-valuable in other situations.

I create all the connection components at runtime and I specifically don't fill in any model attributes anywhere that I'm aware of, so presumably it is just being somehow proactive? Any way to turn that off? If the connection objects (XDataWebConnection or XDataWebClient or whatever) don't have a model specified, not sure why they'd be requesting a blank model, if that's what it is doing?

I believe this is specific to your model. If you create an empty XData server, or even if you create a XData service with the sample methods using the wizard, there is no model or TJSONObject appearing.

The $model URL has nothing to do with ORM or Aurelius, it's the XData model and it lists, for example, all the service endpoints your XData server provides, as long with the data those endpoints receive and respond. It's called only once in your application, so it should also be no issue. It's used by the client to provide you the high-level interface for the XData server. When you use RawInvokeAsync to call a method, say "MyService.Foo", it uses the model to know how to perform the request - the endpoint URL, the parameter types, etc.

Sometimes its the tiniest things that lead to bigger advancements :slight_smile:

For Swagger, I didn't explicity define the model to use (XDataServer object's model was blank) and in the interfaces for the services, no models were specified either, and only service endpoints were defined, no entities, no automatic CRUD, etc. So I added an explicit model to the XDataServer object and to each of the interfaces, but no change. However, I noticed that some of the service endpoints were setup to return a JSONObject. Don't know why. Well, they do return a JSONObject but really these should have been Strings. So I changed the JSONObjects to Strings and voila! No more mysterious model appearing at the bottom of Swagger. I guess XData preps the model section whenever it sees a TJSONObject as that is likely to lead to a model definition? Dunno. In any event, mystery solved and no more empty model. Thanks!!

The seemingly harmless requests for $model, as unrelated as they are (thanks for the clarification!) was actually indicative of a poor design choice on my part. Turns out that I was recreating the TXDataWebConnection each time I was calling RawInvokeAsync, which then generated these $model requests all the time. As you suggested, they should have been appearing only once. As the call to create the XDataWebConnection should have only been once. I rearranged a few things to make the TXDataWebConnection just once and voila! No more extra $model calls and all my server operations now skip the wasteful calls to create the XDataWebConnection each time and as a result my calls to these service endpoints complete in ~160ms instead of ~480ms... Nice improvement :star_struck:

I suppose it was done that way originally as I was working with my "XData Service Endpoint" hat on, thinking that absolutely everything is async and needs to be created/freed during every endpoint operation. Not the case here, certainly.

Thanks very much!!

1 Like