I have a whole bunch of web services each with several web methods. The consumers of these services are varied and many. I want to augment each of these web methods with an extra optional parameter (Int64 or Int32) but adding new methods with this extra (optional parameter) is a lot of work and getting the clients to use the new methods will be even more time consuming.
So I was wondering if I could allow the clients that wanted to take advantage of the new feature that this param provides could pass this Int in the HTTP header or some other way.
So the first question is can I pass an int in the HTTP header? If so, how would one do that in C#/ASP.NET?
Otherwise, what other suggestions do you have for tackling this problem?
In order to pass custom HTTP Headers, you have to build a message using custom HTTP Headers. This is achieved by using MIME Service. Below code snippet (bpml) sets the custom headers and then build the MIME document using MIME Service and then assign the MIME document to PrimaryDocument.
While request header can not contain actual data as mentioned above, you can use request header to send some specific header and based on that you can apply your logic. For instance, while creating a REST API you can send AUTHENTICATION header to verify if request is coming from an allowed user or not.
There are many uses for custom headers and they are quite commonly used. Even if you aren't using a CDN or haven't specifically defined any custom HTTP headers on your origin server, you may still be sending responses with custom headers.
The HTTP headers are used to pass additional information between the clients and the server through the request and response header. All the headers are case-insensitive, headers fields are separated by colon, key-value pairs in clear-text string format.
Its a bit unorthodox and I'm sure some purists would be upset at the idea (the headers should only be used for the transport of the message, and should not contain the semantics of the message).
Practically its doable, but you want to be sure all your clients can add these headers. If your clients are using tools to call the web methods rather than generating the HTTP requests themselves (which I'd hope is the case) then there's a real chance this is a problem.
Why is it so hard to add these additional overloads of the methods?
Yes it is allowed - but note that it may cut off the ability to use proxies and sometimes http aware firewalls (they tend to inspect and rewrite headers).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With