There is a client to WCF service. Some service method is called to send a request. I have at my disposal a MessageInspector that catches the outgoing message and the response received. Let it be BeforeSendRequest (ref Message request, IClientChannel channel). Want to know how to access Mime message headers for editing?
1 answer
It should be understood that the HTTP header is not a header in the understanding of SOAP - it is just some kind of implementation of the transport layer.
However, WCF can provide access to such "implementation details". This is done through the properties of the message, or rather, through the HttpRequestMessageProperty .
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel) { HttpRequestMessageProperty property; object propertyObj; if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out propertyObj)) property = (HttpRequestMessageProperty)propertyObj; else request.Properties.Add(HttpRequestMessageProperty.Name, property = new HttpRequestMessageProperty()); // Теперь делайте с property.Headers что хотите return null; } - Thank you very much! Indeed, it turns out to access the HTTP headers! And do not tell me how you could get to the headers that come after the Soap envelope? - Eric
- @Eric what do you mean? - Pavel Mayorov
- UPD: @PaverMayorov I will try to explain with an example that I understand when using HttpWebRequest and MTOM. With HttpWebRequest, you can add necessary parts to the message in the headers, receive a RequestStream, write the necessary Mime part (Boundary, ContentIp, Content-Type) into it, add coap bytes, and then add the necessary Mime part (Boundary, ContentIp, Content-Type + attachment bytes), and then simple Post to send this request. Is it possible to achieve something like this with WCF? - Eric
- @Eric oh ... I should have said right away that you are using MTOM format - Pavel Mayorov February
- @Eric no, MTOM is generated by WCF in accordance with w3.org/TR/soap12-mtom , no settings are provided here - Pavel Mayorov
|