How can I read Authorization header from a REST based WCF service? - wcf

How can I read Authorization header information from a REST based WCF service?

Actually since you ask for a REST based WCF service I think you should use
WebOperationContext.Current.IncomingRequest.Headers
in order to get the HTTP headers in the request.

You are trying to read the http header.
OperationContext.Current.OutgoingMessageProperties
or
OperationContext.Current.IncomingMessageProperties

Related

How can I make the generated service wsdl (wcf service) contain soap headers?

I have developed a WCF service which use SOAP headers as part of the validation of the request process.
In my service side I verify that the SOAP headers sent and valid.
I generated WSDL files using SOAPUI in order to send to my costumer.
When testing the generated wsdls, I noticed that SOAPUI does not add SOAP headers to the requests automatically.
Is there any way to mark the service (with attribute or something similar) like a service which needs SOAP headers?
Thanks
If you are only using some interceptors / inspectors to validate that header is present you cannot expect that it will be mentioned in WSDL. Header is mentioned in WSDL only if it is part of message contract used by your operation or if you add them to message description manually.

calling a wcf/soap method as an http get

Is there any way to enforce that a method call in soap based wcf is called as an HTTP get? I'm not sure if this would be handled on the client or server side. We wanted to have the wcf call process as a get vs. post for cacheability, etc.
I'm also not sure how to monitor a wcf service to determine if calls are doing gets or posts (or if it always does one or the other). Can I use fiddler for this?
I would imagine I could use a restful wcf service to wrap the call, but I wasn't sure if there was a way to do it straight in a soap based service.
Out of the box WCF functionality does not support SOAP HTTP GET. But WCF is extensible so you can try to develop custom binding (with cutom channel or behavior) supporting this feature.
Caching is supported in WCF 4 REST services. REST services allow all basic HTTP methods.
You can use Fiddler to monitor the gets and posts.
Check out this post about calling a WCF service with an HTTP GET.

WCF BasicHttpBinding Http Post

Is it possible to post to a WCF service hosted in IIS? I know that that this is possible using REST but I really need the WSDL generation and SOAP headers. I need to transition an existing ASMX web services to WCF but I need to also allow my clients to continue to utilize the service via http posts (xml http request via javascript). Is REST my only option?
No, with a SOAP service, you need to use the SOAP methods and actions - you cannot use HTTP POST to "dump" some data on a SOAP service.
If you need HTTP POST, then REST is the way to go.
You can also use REST style WCF
http://msdn.microsoft.com/en-us/netframework/cc950529.aspx

Adding Authorization Header Explicity into WCF client

This question related to this post
Authorization Header is missing in Http request using WCF.
Is there way to explicity add authorization header into Http Request when making WCF call?
I am putting the same answer for this questions too that I put in the another question Authorization Header is missing in Http request using WCF. Because they are related. Actually, I was wrong about this question. I did see different behaviour when running HTTP analyzer. While Http anaylzer running, my application crashed after receiving 401 response. When Http analyzer application closed, the above code worked as expected. Since code worked as expected, authorization header was added by WCF.

How to perform GET web requests to WCF Service Without WCF Client?

I want to send a GET web Request to a WCF service:
for example to:
http://TheirServerIP:PortNumber/TheirService/TheirServiceName.svc?op=theirWCFmethod
i want to write a C# code in my page (web aplication) that send HTTP GET request to their service (without WCF Client)
can i do that ?
To create a WCF service that responds to HTTP GET or HTTP POST requests
http://msdn.microsoft.com/en-us/library/bb628610.aspx
Well, in that case, you need to create a WCF REST service, one that can be called from any language using any HTTP stack and no need for any WCF specifics.
Check out the WCF REST developer center for lots of great info on WCF REST services.
Basically, what it boils down to is
using the WebHttpBinding on your server side
defining a URL pattern to handle requests and their parameters
For the client part of this, use the answer Ladislav provided - just new up a HttpRequest object and make a HTTP GET request to a valid URL - that's all there is, really.
The basic approach to call HTTP resource is:
var request = HttpWebRequest.Create("YourURL");
request.Method = "GET";
var response = request.GetResponse();
...