请检查以下示例
namespace GServices
{
[ServiceKnownType(typeof(SearchType))]
[ServiceContract(SessionMode = SessionMode.Allowed)]
public interface ITest
{
[OperationContract]
int subtract(int x, int y);
}
[ServiceKnownType(typeof(SearchType))]
[ServiceContract(SessionMode = SessionMode.Allowed)]
public interface ITest2
{
[OperationContract]
int add(int x, int y);
}
public class G : ITest2, ITest
{
public int add(int x, int y)
{
return x + y;
}
public int subtract(int x, int y)
{
return x + y;
}
}
}
ITest 有subtract() 方法,Itest2 有add() 方法。
两者都由一个名为 G 的具体类实现。
如果我只想通过 WCF 公开 ITest,我有以下端点配置
<service name="GQS1" behaviorConfiguration="GQwcfBehaviour">
<endpoint address="DP2Svcs" binding="wsHttpContextBinding" bindingConfiguration="wsHttpEndpointBindingConfig" contract="GServices.itest">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
当我运行此服务并检查 wsdl 时,我可以看到 itest2 中的方法也出现在 wsdl 中。在这个例子中,subtract() 方法应该只被暴露。但是 add() 方法也暴露了。
我的要求是 ITest 接口中的方法应该只公开。在这种情况下,我只想公开在 ITest 中声明的减法()方法。但是它们的两个实现都只存在于一个具体的类“G”中。我在这里想念什么?
编辑:我已经给出了我的 Service.svc 文件内容:
<%@ ServiceHost Language="C#" Debug="true" Service="GServices.G" %>