2016-09-12 3 views
0

웹 서비스에서 데이터를 다시받을 때이 오류 메시지가 나타납니다. 나는 오류가 있지만콘텐츠 유형 application/json; 응답 메시지의 charset = utf-8이 바인딩의 내용 유형과 일치하지 않습니다. (텍스트/xml; charset = utf-8)

ChannelFactory<IInterface> factory = new ChannelFactory<IInterface>(new BasicHttpBinding(), new EndpointAddress("http://example.net/MyService.svc/Test")); 
var client = factory.CreateChannel(); 

MyObj x = client.Test(); 

, 나는 오류 메시지의 응답 (JSON 문자열)을 볼 수 있습니다

여기 내 코드입니다. Binding을 WebHttpBinding으로 변경하고 끝점 동작을 WebHttpBehavior으로 추가하는 방법을 시도했지만이 방법은 단순히 null 개체를 반환합니다.

답변

0

해결했습니다. 처음에는 WebHttpBinding을 사용하는 것이 옳았 습니다만, 엔드 포인트 동작을 위해 약간 수정해야했습니다. 작업 코드를 heres :

ChannelFactory<IInterface> factory = new ChannelFactory<IInterface>(new WebHttpBinding(), new EndpointAddress("http://example.net/MyService.svc/Test")); 

WebHttpBehavior behavior = new WebHttpBehavior() 
{ 
    DefaultOutgoingResponseFormat = WebMessageFormat.Json, 
    DefaultBodyStyle = WebMessageBodyStyle.Wrapped, 
    HelpEnabled = true, 
    DefaultOutgoingRequestFormat = WebMessageFormat.Json 
}; 

factory.Endpoint.Behaviors.Add(behavior); 

var client = factory.CreateChannel(); 

MyObj x = client.Test();