Read SOAP message header WCF - wcf

I have a WCF service with ws-security using wsHttpBinding. In one of my method, I want to read the ws-security SOAP header. How do I do it?
I have visited this link but not getting idea. I simply want to read the soap header in one of the operation contract in my WCF service.
Is it possible to receive a soap message in a WCF method?
Thanks,
Jay

Jay,
Yes is possible to receive a SOAP message in a WCF method, but what I think you want is to read the header variables in the inbound request.
On the host side, create an object from this:
System.ServiceModel.OperationContext.Current.IncomingMessageHeaders
This will return an indexed collection of the inbound message headers sent from the client, and you can read it this way:
OpContext.IncomingMessageHeaders(0).ToString

Related

WCF, wsHttpBinding and ws-addressing: The field <wsa:From> is missing from the soap messages

I implemented a wcf web service by using wsHttpBinding. The SOAP message perfectly includes some of the important ws-addressing fields inlcuing wsa:MessageID, wsa:ReplyTo, wsa:To and wsa:Action.
The problem is that wsa:From filed is missing from the SOAP messages. Is there any way to have wsa:From in the soap messages when I use wsHttpBinding?
Thank you,

Where is SoapAction configured in WCF Client?

I need my wcf client to communicate with the service with a blank SoapAction because the service is configured to dispatch the operation by body of the soap message. And the operation contract is decorated as below so it will not require soap action. I guess WCF sends a soapaction by default. Is there any option in wcf client to send a blank soapaction? Thanks for any help!
[OperationContract(Action="")]
use the same OperationContract attribute on your client code, i.e. reference.cs. More details here.

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.

How to get the soap or http request object from a wcf class

From a wcf4 service need to access to the underlying http request,including it's soap message, how can I do that from code?, I know I can use fiddler, etc, but need to do it programatically.
Look at Message Inspectors.

WCF how to pass token for authentication?

I have a WCF service which would like to support basicHttpBinding and webHttpBinding. When the client successfully login, server will generate a token for client to pass to server on all the request make later. Question is how the client can pass the token to server? I don't want to add an extra parameter on every web method to hold the token.
Typically, the best way to do something like this is passing such "meta-information" in a WCF header. You can easily create a message inspector to extend WCF (it's really not that scary and hard to do!) which would inject the token into every outgoing request from the client, and retrieve it from the header and validate it on the server side.
There are a number of pretty good blog post out there showing you how to create a message inspector:
Richard Hallgren's WCF postings
Writing a WCF message inspector
Automatic Culture Flowing with WCF by using Custom Behaviour
Check out the two relevant interfaces to implement:
IClientMessageInspector on the client side, which has a BeforeSendRequest and AfterReceiveReply message to implement
IDispatchMessageInspector on the server side, which has a AfterReceiveRequest and BeforeSendReply method to implement