WCF Web Service error: “Service endpoint binding not using HTTP protocol”?

后端 未结 8 936
无人及你
无人及你 2021-01-04 12:58

I\'ve got a simple WCF service that has worked fine while I\'ve been testing on my dev machine.

Now I\'ve moved the web service to a web server, and I\'m running the

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 13:20

    Late answer to the party, but I got the same error.

    Turns out, you cannot use abstract classes for data contract members. I had to use the following:

    [DataContract]
    public class MyClass {
        [DataMember]
        public A MyProperty { get; set; }
    }
    
    [DataContract]
    [KnownType(typeof(B))]
    [KnownType(typeof(C))]
    public class A {
    
    }
    
    [DataContract]
    public class B : A {
    
    }
    
    [DataContract]
    public class C : A {
    
    }
    

    In order to allow WCF to serialize something like

    var myClass = new MyClass();
    myClass.MyProperty = new B();
    

提交回复
热议问题