Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net WCF中通过SOAP和REST端点选择性公开方法的设计模式_.net_Wcf_Web Services_Rest_Soap - Fatal编程技术网

.net WCF中通过SOAP和REST端点选择性公开方法的设计模式

.net WCF中通过SOAP和REST端点选择性公开方法的设计模式,.net,wcf,web-services,rest,soap,.net,Wcf,Web Services,Rest,Soap,我有一个WCF web服务,它定义了接口接口。这个接口声明了两个方法:Method1和method2。我希望通过SOAP端点公开这两个方法,但只希望通过REST端点公开Method2 声明示例: [ServiceContract] public Interface IInterface { [OperationContract] void Method1(); [OperationContract] void Method2(); } public class

我有一个WCF web服务,它定义了接口接口。这个接口声明了两个方法:Method1和method2。我希望通过SOAP端点公开这两个方法,但只希望通过REST端点公开Method2

声明示例:

[ServiceContract]
public Interface IInterface
{
    [OperationContract]
    void Method1();
    [OperationContract]
    void Method2();
}

public class MyService : IInterface
{
    public void Method1(){...}
    public void Method2(){...}
}
到目前为止,我已经尝试创建了两个额外的接口:
IInterfaceSOAP
IInterfaceREST
,它们都是从
IInterface
继承的。从
IInterface
中删除
Method2()
声明,并将其添加到
IInterfaceSOAP
中,并创建了两个独立的类
MyServiceSOAP:IInterfaceSOAP
myServiceList:IInterfaceREST
。然后为每个派生类定义两个独立的端点

但是当我使用
WcfTestClient
测试服务时,soap服务只列出
Method1()
(在基本
IInterface
中定义的服务)

上述模式是通过两个独立端点选择性公开方法的公认解决方案吗?还是我错过了其他一些方法

提前谢谢


另外,请注意,上面的界面是我试图做的极其简化的版本。在生产版本中有更多的方法。

这种方法似乎有点难闻,因为您的服务合同和实现中泄漏了部署问题。鉴于REST无论如何都不公开元数据,我看不出不同接口有什么好处


我认为一个行为或ServiceAuthorizationManager(它检查消息版本并禁止对REST请求的访问)将是一个更干净的解决方案。这样,您就可以为单个契约实现单个服务,并将协议问题推回到它们所属的位置:部署和配置。。。由于大量的方法,我错过了方法2。因为它是在派生接口中定义的,所以基本接口中的所有方法都在这个方法之前,我错过了它。

我确实在web.config中定义了端点和行为。我试图实现的只是SOAP和REST端点的代码重用,但有选择地禁止REST中的某些方法。@Dimitri我不太清楚如何使用差异化接口实现代码重用,因为您说有两种实现—每个差异化接口一种。我建议您对REST接口施加的限制可能只是一个部署问题,因此应该反映在那里,而不是在契约/实现中。我有一个基本接口,它包含了我想在REST和SOAP中使用的大多数方法。然后,我为上述每种类型的服务派生两个接口。soapone有我想要公开的其他方法,但其余的没有。现在,当我从这两个接口派生类时,实现只存在于从SOAP接口派生的类中(实现了所有方法),但从REST接口派生的类只调用SOAP类中所需的方法。