Using a method not mentioned in OperationContract
I have WCF services. It has two methods like Get and Save. I want to expose only the Get method to a third party that will consume the service, while my application needs to be able to use both Get and Save.
Is there a way to use a method other than OperationContract? I am thinking about validating the hostname of the request and only granting access if it is the hostname of my application.
source to share
Why not create a second ServiceContract
one that has both Get
how and Set
how OperationContracts
? Then you can block who can go to this second contract.
[ServiceContract]
public interface IFoo
{
[OperationContract]
void Get();
}
[ServiceContract]
public interface IFooInternal : IFoo
{
[OperationContract]
void Set();
}
source to share
Here is the code to identify the host's 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";
}
source to share