我正在尝试使用WCF服务从基类返回派生类,但是我不断收到以下异常
"An error occurred while receiving the HTTP response to http://localhost:50137/Service.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server..."
我尝试通过WCF Service方法添加以下所有内容。
1) [XmlInclude(typeof(DerivedClass1)), XmlInclude(typeof(DerivedClass2))]
2) [SoapRpcMethod]
3) [SoapInclude(typeof(DerivedClass1)), SoapInclude(typeof(DerivedClass2))]
码:
public class BaseClass
{
}
public class DerivedClass1:BaseClass
{
}
public class DerivedClass2:BaseClass
{
}
Run Code Online (Sandbox Code Playgroud)
Wcf服务方法:
public BaseClass Validate()
{
if(someCondition)
return new DerivedClass1();
else
return new DerivedClass2();
}
Run Code Online (Sandbox Code Playgroud)
小智 6
[Serializable]
[DataContract]
[
KnownType(typeof(DerivedClass1)),
KnownType(typeof(DerivedClass2))
]
public class BaseClass
{
}
public class DerivedClass1:BaseClass
{
}
public class DerivedClass2:BaseClass
{
}
Run Code Online (Sandbox Code Playgroud)
有关已知类型和通用解析器的更多信息,请参见 https://msdn.microsoft.com/zh-cn/magazine/gg598929.aspx。
| 归档时间: |
|
| 查看次数: |
853 次 |
| 最近记录: |