Return 继承 Class 到基础 Class WCF 服务
Return Inherited Class into Base Class WCF Service
我正在尝试使用 WCF 服务从基础 class return 派生 class,但我不断收到以下异常
"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 服务方法添加以下所有内容。
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
{
}
Wcf服务方式:
public BaseClass Validate()
{
if(someCondition)
return new DerivedClass1();
else
return new DerivedClass2();
}
您发布的代码存在一些问题:
- 您的合约类型和操作代码没有ServiceModel注解
- 您尚未指定托管服务的方式
- 您尚未指定调用服务的方式
- 您还没有指定任何有关您正在使用的绑定的信息
在至少其中一些问题得到澄清之前,我认为这个问题是无法回答的。如果您可以编辑您的问题以包含这些要点,我将编辑我的答案。
[Serializable]
[DataContract]
[
KnownType(typeof(DerivedClass1)),
KnownType(typeof(DerivedClass2))
]
public class BaseClass
{
}
public class DerivedClass1:BaseClass
{
}
public class DerivedClass2:BaseClass
{
}
见
https://msdn.microsoft.com/en-us/magazine/gg598929.aspx 了解有关已知类型和通用解析器的更多信息。
我正在尝试使用 WCF 服务从基础 class return 派生 class,但我不断收到以下异常
"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 服务方法添加以下所有内容。
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
{
}
Wcf服务方式:
public BaseClass Validate()
{
if(someCondition)
return new DerivedClass1();
else
return new DerivedClass2();
}
您发布的代码存在一些问题:
- 您的合约类型和操作代码没有ServiceModel注解
- 您尚未指定托管服务的方式
- 您尚未指定调用服务的方式
- 您还没有指定任何有关您正在使用的绑定的信息
在至少其中一些问题得到澄清之前,我认为这个问题是无法回答的。如果您可以编辑您的问题以包含这些要点,我将编辑我的答案。
[Serializable]
[DataContract]
[
KnownType(typeof(DerivedClass1)),
KnownType(typeof(DerivedClass2))
]
public class BaseClass
{
}
public class DerivedClass1:BaseClass
{
}
public class DerivedClass2:BaseClass
{
}
见 https://msdn.microsoft.com/en-us/magazine/gg598929.aspx 了解有关已知类型和通用解析器的更多信息。