2009-05-04 23 views
0

我有一个WCF服务。有两种方法,Get和Save。我只想将Get方法公开给将要使用服务的第三方,而我的应用程序应该能够同时使用Get和Save。使用OperationContract中未提及的方法

有没有办法消耗OperationContract中的方法?我正在考虑验证请求的主机名并仅在它是我的应用程序的主机名时授予访问权。

回答

4

为什么不创建第二个ServiceContractGetSetOperationContracts?然后你可以锁定谁可以得到这个第二份合同。

[ServiceContract] 
public interface IFoo 
{ 
    [OperationContract] 
    void Get(); 
} 

[ServiceContract] 
public interface IFooInternal : IFoo 
{ 
    [OperationContract] 
    void Set(); 
} 
0

这里是要找出主机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"; 
} 
相关问题