WCF端点协定名称——如果它是泛型的,如何分配它? IGenericService驻留在名为“ABC.Server.Common”(ABC.Server.Common.dll)的程序集中 MyType驻留在名为“ABC.Server.Modules.X”的程序集中(ABC.Server.Modules.X.dll)

WCF端点协定名称——如果它是泛型的,如何分配它? IGenericService驻留在名为“ABC.Server.Common”(ABC.Server.Common.dll)的程序集中 MyType驻留在名为“ABC.Server.Modules.X”的程序集中(ABC.Server.Modules.X.dll),wcf,generics,endpoint,contract,Wcf,Generics,Endpoint,Contract,代码: 公共类ABC.Server.Modules.XService: ABC.Server.Common.IGenericService { ABC.Server.Common.GenericResponse DoFoo(ABC.Server.Common.GenericRequest请求) { //在这里做事 } } 压缩代码: 公共类XService: IGenericService { GenericResponse DoFoo(GenericRequest请求) { //在这里做事

代码:

公共类ABC.Server.Modules.XService:
ABC.Server.Common.IGenericService
{
ABC.Server.Common.GenericResponse DoFoo(ABC.Server.Common.GenericRequest请求)
{
//在这里做事
}
}
压缩代码:

公共类XService:
IGenericService
{
GenericResponse DoFoo(GenericRequest请求)
{
//在这里做事
}
}
Web.config:
我不使用SVC文件,而是在Web.config中处理这些信息:

<add factory="System.ServiceModel.Activation.ServiceHostFactory"
     relativeAddress="Services/X.svc"
     service="ABC.Server.Modules.X.XService"/>

<service name="ABC.Server.Modules.X.XService"
         behaviorConfiguration="StandardBehavior">
  <endpoint bindingConfiguration="StandardBinding"
            binding="basicHttpBinding"
            contract="?" />
</service>


我应该在合同名称中添加什么才能使其实际工作?

通常,您可以通过以下代码片段了解WCF希望您为合同名称添加什么:

ContractDescription.GetContract(typeof(IGenericService<MyType>)).ConfigurationName
ContractDescription.GetContract(typeof(IGenericService)).ConfigurationName

通常,您可以通过以下代码片段了解WCF希望您为ContractName添加的内容:

ContractDescription.GetContract(typeof(IGenericService<MyType>)).ConfigurationName
ContractDescription.GetContract(typeof(IGenericService)).ConfigurationName

请参见:或:通常不建议这样做-WCF无法很好地处理泛型,因为它需要具有互操作性,并且必须能够用XML模式定义来表示服务契约上的所有内容,而XML模式不做泛型…@marc_s:我认为WCF可以很好地处理泛型,因为它静态地键入内容:IGenericService变成IGenericService of_TypeT或类似的东西。您需要保留两个除此之外:(1)在WCF服务内部,它是纯.NET编程,您可以使用任何喜欢的.NET功能(包括泛型等),但是(2)在WCF外部,您需要具有互操作性,据我所知,很多语言和系统都不支持泛型-包括用于描述WCFSee提供的服务的XML模式:或者:通常不建议这样做-WCF无法很好地处理泛型,因为它需要具有互操作性,并且必须能够用XML模式定义来表示服务契约上的所有内容,而XML模式不做泛型…@marc_s:我认为WCF可以很好地处理泛型,因为它静态地键入内容:IGenericService变成IGenericService of_TypeT或类似的东西。您需要保留两个除此之外:(1)在WCF服务内部,它是纯.NET编程,您可以使用任何喜欢的.NET功能(包括泛型等),但是(2)在WCF外部,您需要具有互操作性,据我所知,很多语言和系统都不支持泛型,包括用于描述WCF提供的服务的XML模式
ContractDescription.GetContract(typeof(IGenericService<MyType>)).ConfigurationName