So, there are two main things that should happen:
- Get cookie from web application context to WCF service
- Get cookie from WCF service ASMX service
NOTE. . Since you did not specify, I assume that you are using the WCF client in your WCF service to talk to the ASMX service. If this is not the case, please let me know and I will revise this message accordingly.
Step 1:
IClientMessageInspector, , IEndpointBehavior. IClientMessageInspector:: BeforeSendRequest cookie HttpContext:: Request:: Cookies . :
public void BeforeSendRequest(ref Message request, IClientChannel channel)
{
string cookieValue = HttpContext.Current.Request.Cookies["MyCookieName"].Value;
MessageHeader myCookieNameHeader = MessageHeader.CreateHeader("MyCookieHeaderName", "urn:my-custom-namespace", cookieValue);
request.Headers.Add(myCookieNameHeader);
}
. , cookie WCF. , WCF , . , , .
# 2:
, cookie WCF ASMX. IClientMessageInspector, , BeforeSendMessageRequest :
public void BeforeSendRequest(ref Message request, IClientChannel channel)
{
string cookieValue = OperationContext.Current.IncomingMessageHeaders.GetHeader<string>("MyCookieHeaderName", "urn:my-custom-namespace");
HttpRequestMessageHeaderProeperty httpRequestMessageHeaderProperty;
MessageProperties outgoingMessageProperties = OperationContext.Current.OutgoingMessageProperties;
if(!outgoingMessageProperties.TryGetValue(HttpRequestMessageHeaderProperty.Name, out httpRequestMessageHeaderProperty))
{
httpRequestmessageHeaderProperty = new HttpRequestMessageHeaderProperty();
outgoingMessageProperties.Add(HttpRequestMessageHeaderProperty.Name, httpRequestmessageHeaderProperty);
}
httpRequestmessageHeaderProperty.Headers[HttpRequestHeader.Cookie] = cookieValue;
}
ASMX IEndpointBehavior, , , cookie .