我有一个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";
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top