WCF端点合同名称 - 如果它是通用的,如何分配它?

mic*_*ael 0 generics wcf contract endpoint

  • IGenericService驻留在名为"ABC.Server.Common"(ABC.Server.Common.dll)的程序集中
  • MyType驻留在名为"ABC.Server.Modules.X"(ABC.Server.Modules.X.dll)的程序集中

码:

public class ABC.Server.Modules.XService :
    ABC.Server.Common.IGenericService<ABC.Server.Module.X.MyType>
{
    ABC.Server.Common.GenericResponse<ABC.Server.Module.X.MyType> DoFoo(ABC.Server.Common.GenericRequest<ABC.Server.Module.X.MyType> request)
    {
        //Do Stuff Here
    }
}
Run Code Online (Sandbox Code Playgroud)

简明代码:

public class XService :
    IGenericService<MyType>
{
    GenericResponse<MyType> DoFoo(GenericRequest<MyType> request)
    {
        //Do Stuff Here
    }
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

我如何在合同名称中加入实际工作?

ale*_*dej 5

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

ContractDescription.GetContract(typeof(IGenericService<MyType>)).ConfigurationName
Run Code Online (Sandbox Code Playgroud)