2012-08-28 2 views
1

WCF 웹 서비스에서 작업 중입니다. 내가 JavaScriptSerializer().Serialize() 를 사용하여 객체를 직렬화하고이 메시지에서WebInvoke는 추가 인용 부호가있는 Json 문자열을 반환합니다.

[WebInvoke(UriTemplate = "GetMatAnalysis", ResponseFormat = WebMessageFormat.Json, 
               RequestFormat = WebMessageFormat.Json, 
               BodyStyle = WebMessageBodyStyle.WrappedRequest, 
               Method = "POST")] 
string GetMatAnalysis(Stream image); 

를 다음 반환 : 나는 다음과 같이 JSON의 stringhe 서비스가 선언 반환 후 서비스를 만들어야합니다.

그러나 응답을 받으면 문자열의 처음과 끝에 여분의 큰 따옴표가 있습니다. 예를 들어 나는 점점 오전 : "{"results" : 10 }" 대신 내가 System.ServiceModel.Channels.Message에 반환 형식을 변경하려고

{"results" : 10 }의 난이 오류가 발생합니다 :

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: 
System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:IMyWebServices ----> System.InvalidOperationException: The operation 'GetMatAnalysis' could not be loaded because it has a parameter or return type of type System.ServiceModel.Channels.Message or a type that has MessageContractAttribute and other parameters of different types. When using System.ServiceModel.Channels.Message or types with MessageContractAttribute, the method must not use any other types of parameters. 

어떻게 그것을 따옴표없이 JSON 문자열을 반환 할 수 있습니까?

추가 정보 :

이 같은 GET 요청을 사용

[OperationContract(Name = "Messages")] 
[WebGet(UriTemplate = "Messages/GetMessage", ResponseFormat = WebMessageFormat.Json)] 
Message GetAdvertisment(); 

반환 형식 메시지이고 제대로 작동합니다. 받은 Json 문자열이 정확합니다.

도움을 주시면 대단히 감사하겠습니다. 감사합니다.

+0

저는 이것이 MS의 귀찮은 단점이라고 생각합니다. 다시 한번 그들은 자체 트위스트 로직을 사용하여 표준을 적용하고 있습니다. – Liam

+0

@ L.B 감사합니다. 그것을 받아들이는 대답으로 쓰십시오. – Youssef

답변

1

ResponseFormat = WebMessageFormat.Json 이래로 WCF 서비스는 반환 된 개체를 Json으로 serialize합니다. JavaScriptSerializer().Serialize()도 사용하면 이중 직렬화가됩니다.

+4

k 어떻게 고쳐 주십니까? – kschieck

관련 문제