locked
WCF Service not returning RRS feed

  • Question

  • I have a Class where all the content goes in; so that errors and every response stays consistent:

    #region Class
        /// <summary>
        /// This class is used in every response which is sent out by this service.
        /// </summary>
        [Serializable]
        [DataContract]
        public class JSONOutput
        {
            #region Fields
            /// <summary>Type of response (OK, param_error)</summary>
            [DataMember]
            public String Type { get; set; }
    
            /// <summary>Code for the response</summary>
            [DataMember]
            public String Code { get; set; }
    
            /// <summary>Error detail</summary>
            [DataMember]
            public String Error { get; set; }
    
            /// <summary>Actual JSON response</summary>
            [DataMember]
            public Object Response { get; set; }
            #endregion Fields
        }
        #endregion Class

    This is what my Contract looks like

            [OperationContract]
            [WebInvoke(Method = "GET", UriTemplate = "/GetData?venueId={venueId}",
                ResponseFormat = WebMessageFormat.Json)]
            JSONOutput GetData(String venueId);

    Now, in my implementation of GetData Method.

    If I do this: (Works)

    return Response.OKContentResponse("Success");

    But If I do this:

    Data[] dataList = GetDataList();
                return Response.OKContentResponse(dataList);

    This doesn't work; The WCF service doesn't return anything. In debugging, this function hits twice and then nothing; but the data is there. Something is going wrong at Serialization.

            internal static JSONOutput OKContentResponse(Object content)
            {
                JSONOutput valid = new JSONOutput()
                {
                    Code = ResponseCodes.OKResponse.Value(),
                    Type = ResponseCodes.OKType.Value(),
                    Response = content
                };
                return valid;
            }

    I was wondering if someone knows what maybe going wrong.

    Really appreciate for the help.

    Harsimrat

    Wednesday, December 11, 2013 2:34 AM

Answers

  • Hi,

    It seems that it has something wrong with the Json serialization.

    Please add the following block to your web.config <configuration> block:

      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true">
            <listeners>
              <add name="traceListener"
                  type="System.Diagnostics.XmlWriterTraceListener"
                  initializeData="c:\log\WebTrace.svclog"  />
            </listeners>
          </source>
        </sources>
      </system.diagnostics>

    and ensure the directory specified (c:\log) exists and is writable by the IIS service.

    Once this is done, perform the action that causes the serialization issue then navigate to the directory and double-click the generated svclog file.

    This will open the file in the Microsoft Service Trace Viewer. Once this is opened, you will see errors displayed in red down the left-hand side.

    Clicking on one of these will show the details in the top right pane and you can click on each of the actions to determine what WCF is complaining about.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by thukralz Friday, December 13, 2013 7:37 AM
    Thursday, December 12, 2013 7:34 AM

All replies

  • Hi,

    It seems that it has something wrong with the Json serialization.

    Please add the following block to your web.config <configuration> block:

      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true">
            <listeners>
              <add name="traceListener"
                  type="System.Diagnostics.XmlWriterTraceListener"
                  initializeData="c:\log\WebTrace.svclog"  />
            </listeners>
          </source>
        </sources>
      </system.diagnostics>

    and ensure the directory specified (c:\log) exists and is writable by the IIS service.

    Once this is done, perform the action that causes the serialization issue then navigate to the directory and double-click the generated svclog file.

    This will open the file in the Microsoft Service Trace Viewer. Once this is opened, you will see errors displayed in red down the left-hand side.

    Clicking on one of these will show the details in the top right pane and you can click on each of the actions to determine what WCF is complaining about.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by thukralz Friday, December 13, 2013 7:37 AM
    Thursday, December 12, 2013 7:34 AM
  • Seems like the issue is with Serialization:

    Type 'Entity.v1.Model.Info' with data contract name 'UserInfo:http://schemas.datacontract.org/2004/07/Entity.v1.Model' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

    Thursday, December 12, 2013 8:07 AM
  • Interestingly if I return the Info directly as the method return type; it serializes it absolutely fine. The problem starts when I put it in the JSONoutput class and then try to serialize the whole thing.
    Thursday, December 12, 2013 8:13 AM
  • Adding known Type does the trick. Now all my objects need to go through this class; is there a better way to add knownTypes or everytime I do something, it has to go in there ?
    Thursday, December 12, 2013 8:30 AM