使用OperationContract中未提及的方法
题
我有一个WCF服务。其中有两种方法,比如Get和Save。我想只将Get方法暴露给将要使用该服务的第三方,而我的应用程序应该能够同时使用Get和Save。
有没有办法使用不在OperationContract中的方法?我正在考虑验证请求的主机名,并仅在它是我的应用程序的主机名时授予访问权限。
解决方案
为什么不创建第二个 ServiceContract
,其中获取
和设置
为 OperationContracts
?然后你可以锁定谁可以达到第二份合同。
[ServiceContract]
public interface IFoo
{
[OperationContract]
void Get();
}
[ServiceContract]
public interface IFooInternal : IFoo
{
[OperationContract]
void Set();
}
其他提示
以下是识别主机IP地址的代码:
string GetAddressAsString()
{
RemoteEndpointMessageProperty clientEndpoint =
OperationContext.Current.IncomingMessageProperties[
RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
if (clientEndpoint != null)
{
return String.Format("{0}:{1}", clientEndpoint.Address, clientEndpoint.Port);
}
return "Failed to identify address";
}
不隶属于 StackOverflow