Silverlight 응용 프로그램에서 RIA DomainService로 보낸 각 요청에 사용자 정의 헤더를 추가하려고합니다.Silverlight + Google 크롬 + 사용자 정의 요청 헤더 => 내용 유형 오류
도메인 클라이언트의 끝점의 동작 컬렉션에 사용자 지정 동작을 추가하여이 작업을 수행하고 있습니다.
내 동작은 다음 사용자 지정 헤더를 요청에 설정하는 사용자 지정 MessageInspector를 추가합니다.
이 모든 것이 IE에서는 좋지만 Chrome에서는 예외가 발생합니다. "... 콘텐츠 유형 text/plain; 응답 메시지의 charset = x 사용자 정의가 콘텐츠 유형과 일치하지 않습니다. 바인딩 (응용 프로그램/msbin1) ... ".
RIA 서비스 요청에 맞춤 헤더를 추가하고 Chrome에서 작동시키는 데 성공한 사람이 있습니까? 누군가 이걸 가지고 나를 도울 수 있습니까?
여기 내 사용자 정의 행동의 코드입니다 :
public class AppendExtraHeadersHttpBehavior : WebHttpBehavior
{
public AppendExtraHeadersHttpBehavior()
{
}
public override void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.MessageInspectors.Add(m_inspector);
}
private readonly AppendExtraHeadersMessageInspector m_inspector = new AppendExtraHeadersMessageInspector();
}
여기 내 사용자 지정 메시지 속성의 코드입니다 :
public class AppendExtraHeadersMessageInspector : IClientMessageInspector
{
public AppendExtraHeadersMessageInspector()
{
}
public void AfterReceiveReply(ref Message reply, object correlationState)
{
// Nothing to do here.
}
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
var property = request.Properties[ HttpRequestMessageProperty.Name ] as HttpRequestMessageProperty;
if(property != null)
{
property.Headers[ "CultureName" ] = Thread.CurrentThread.CurrentCulture.Name;
}
return null;
}
}
그리고 마지막으로, 여기에 내가 내 DomainContext에 대한 부분에 추가 된 코드입니다.
partial void OnCreated()
{
var domainClient = this.DomainClient as WebDomainClient<IMyServiceContract>;
if(domainClient != null)
{
domainClient.ChannelFactory.Endpoint.Behaviors.Add(AppendExtraHeadersHttpBehavior);
}
}
private static readonly AppendExtraHeadersHttpBehavior AppendExtraHeadersHttpBehavior = new AppendExtraHeadersHttpBehavior();
미리 감사드립니다.
감사합니다. 문제를 해결했습니다. 그래도 "HasSideEffects"에 영향을 줄 때 무엇이 변경 될까요? 나는 이것이 웹 캐싱에 영향을 미칠 것이라는 것을 알고 있지만, 다른 것이 있습니까? –
http 메소드는 POST입니다. GET 및 POST HTTP 메소드 간의 차이점을 고려해야 할 수도 있습니다. 하나는 매개 변수를 URL의 일부로 전달하지 않는다는 것입니다. – marce
고마워, 내가 살펴볼거야. –