我有一个WCF服务。它有两个方法,即Get和Save。我只想将Get方法公开给将使用该服务的第三方,而我的应用程序应该能够同时使用Get和Save。
有没有一种方法可以使用OperationContract以外的方法?我正在考虑验证请求的主机名,并仅当它是我的应用程序的主机名时才授予访问权限。
发布于 2009-05-04 10:57:43
为什么不创建另一个同时包含Get和Set作为OperationContracts的ServiceContract?然后你就可以锁定谁可以获得第二份合同。
[ServiceContract]
public interface IFoo
{
[OperationContract]
void Get();
}
[ServiceContract]
public interface IFooInternal : IFoo
{
[OperationContract]
void Set();
}发布于 2010-01-20 06:29:12
以下是标识主机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";
}https://stackoverflow.com/questions/819643
复制相似问题