WCF method called twice

前端 未结 7 984
一个人的身影
一个人的身影 2021-02-02 15:41

I have a web service which is returning data to the desktop application. The problem I am having is, when the web service returns small volume of data everything works fine but

相关标签:
7条回答
  • 2021-02-02 16:32

    I recently had this issue.

    It turned out that analyzing the WCF log as written by the System.Diagnostics.XmlWriterTraceListener yielded a problem with the data contract I had set up.

    I am returning Dictionary<int, object> (Side Note: Yes, I know this is really bad!, but I am young and need the money). I forgot to include the [KnownType] attribute on the return value for the DataContract:

        [DataContract]
        [KnownType(typeof(Dictionary<int, double>))]
        [KnownType(typeof(Dictionary<int, ChannelData>))]
        [KnownType(typeof(Dictionary<string, Dictionary<int, double>>))]
        public class MyCoolObject: ICoolObject
        {
    [DataMember]
            public Dictionary<string, object> Results
            {
                get { return _results; }
                set { _results = value; }
            }
        }
    
    0 讨论(0)
  • 2021-02-02 16:37

    I too had this issue. For me, it was happening because I had a [DataMember] property with a get{} but no set{}. After adding a set{} this behavior stopped.

    0 讨论(0)
  • 2021-02-02 16:40

    I encountered this same problem. It turned out WCF couldn't return DateTime as JSON, so I had to make it Nullable<DateTime>.

    0 讨论(0)
  • 2021-02-02 16:42

    It could be because the size of the message is greater than the default message size. You might try increasing the this value in the configuration of the endpoint. You could also take a look at this post.


    UPDATE:

    To further diagnose the problem I would suggest you activating the trace on the service by putting the following in the config file:

    <system.diagnostics>
        <trace autoflush="true">
        </trace>
        <sources>
            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
                <listeners>
                    <add name="sdt"
                         type="System.Diagnostics.XmlWriterTraceListener"
                         initializeData="WcfDetailTrace.e2e" />
                </listeners>
            </source>
        </sources>
    </system.diagnostics>
    

    This will generate the WcfDetailTrace.e2e trace file which you could open with the Service Trace Viewer Tool which will provide you with extensive information about the call and the error message.

    0 讨论(0)
  • 2021-02-02 16:43

    I also had this problem and my solution was similar to Batgar's, but with a twist. I had a class that had a property of type object. I had to add KnownType attributes to the class for every type the object could hold. I couldn't populate the KnownType on-the-fly as the class didn't know what the object will contain.

    0 讨论(0)
  • 2021-02-02 16:46

    I recently had this problem, and it turned out i have forgotten to mark one of the data transfer classes with [DataContract]

    0 讨论(0)
提交回复
热议问题