views:

144

answers:

2

I have a WCF services. Which has two methods, say Get and Save. I want to expose only the Get method to the third party who will be consuming the service while my application should be able to consume both Get and Save.

Is there a way to consume a method not in OperationContract? I am thinking of verifying the host name of the request and granting access only if it is the host name of my application.

+4  A: 

Why not create a second ServiceContract that has both Get and Set as OperationContracts? Then you could lock down who can get to this second contract.

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

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

Here is the code to identify the host ip address:

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";
}
Adam Berent