asp.net web api: relative urls

792 views Asked by At

I'm migrating from wcf data services to asp.net web api odata and I'm having problems using relative URLs. I'm trying to implement the functionality which is described in this article (adding relationships between entities):

http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/entity-relations-in-odata-v4

I'dont know if this is due to the protocol specification of v4 of the odata protocol, but working with relative URLs was defnitly doeable with odata v3 and wcf data services.

The problem is, that absolute urls don't work if you are behind a reverse proxy. If you specify a relative URL in the request

PUT http://myproductservice.example.com/Products(6)/Supplier/$ref HTTP/1.1
OData-Version: 4.0;NetFx
OData-MaxVersion: 4.0;NetFx
Accept: application/json;odata.metadata=minimal
Accept-Charset: UTF-8
Content-Type: application/json;odata.metadata=minimal
User-Agent: Microsoft ADO.NET Data Services
Host: myproductservice.example.com
Content-Length: 70
Expect: 100-continue

{"@odata.id":"Suppliers(4)"}

you get an exception that clearly states that relative urls are only allowed in combination with an odata context - so you have to know the absolut URL either way. Is there a solution so that you can work around this issue and use relative URLs? At least: How does this work in combination with a load balancer, reverse procxy etc.

Update

as I see it, relative URLs should be possible even without odata context (form odata v4 spec http://docs.oasis-open.org/odata/odata-json-format/v4.0/cs01/odata-json-format-v4.0-cs01.html#_Toc365464682):

URLs present in a payload (whether request or response) MAY be represented as relative URLs.

If a context URL is present in the same JSON object as the relative URL or an enclosing object, the relative URL is relative to the next context URL. This rule also applies to context URLs; they can be relative to the context URL of an enclosing object.

If no context URL is present in a request, relative URLs are relative to the request URL.

If no context URL is present in a response, relative URLs are relative to the Content-Location header of the response.

In responses without a Content-Location header or context URL, relative URLs are relative to the request URL.

Processors expanding the URLs MUST use normal URL expansion rules as defined in [RFC3986]. This means that if the base URL is a context URL, the part starting with $metadata# is ignored when resolving the relative URL.


Has someone else gone the migration path from wcf data service to web api odata and does know some good resources to read? AFAIK it was promised to open source WCF data services, what happened to that?

0

There are 0 answers