2009-05-04 28 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"; 
} 
相關問題