WCF 서비스의 일부 끝점을 보안하려는 경우 일부 끝점과 일부 끝점을 보호 할 수 있는지 여부를 알 수 없습니다. 아래에는 WCF 서비스 (자체 호스팅 됨)가 제거되었습니다. 동일한 WCF는 CA 정책 파일에도 사용됩니다. 이 WCF 서비스 또는 일부 끝점 ut의 CA 정책 부분에 사용자 이름 암호를 묻지 않아야합니다. 항상 정책 파일에 액세스 할 수 있어야합니다. 그게 가능하니?사용자 지정 인증을 사용하여 WCF 서비스 끝점 보안
많은 WCF 맞춤 블로그/게시물을 발견했습니다. 보안을 수행 할 수있는 많은 방법이 있습니다. 필자가 원하는 것은 사용자 이름/암호로 일부 종점을 보호 할 수 있지만 피들러와 같은 도구로 자격 증명을 표시하면 안됩니다. 그러나이 경우 데이터를 볼 수 있습니다.
이미 Customvalidator를 구현했지만 app.config 파일도 가져올 항목을 정의합니다. 그리고 저는 그것에 능숙하지 않습니다.
namespace WindowsFormsApplication11
{
public partial class Form1 : Form
{
public ServiceHost _host = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Create a ServiceHost for the CalculatorService type and
// provide the base address.
_host = new ServiceHost(typeof(WmsStatService));
_host.AddServiceEndpoint(typeof(IPolicyProvider), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());
_host.Open();
}
}
// Define a service contract.
[ServiceContract(Namespace = "http://WindowsFormsApplication11")]
public interface IWmsStat
{
[OperationContract]
string getConnectedViewers(string channelName);
[OperationContract]
string sayHello(string name);
}
[ServiceContract]
public interface IPolicyProvider
{
[OperationContract, WebGet(UriTemplate = "/ClientAccessPolicy.xml")]
Stream ProvidePolicy();
}
//[DataContract]
public class Ads
{
// [DataMember]
public string AdFileName { get; set; }
//[DataMember]
public string AdDestenationUrl { get; set; }
public string ConnectedUserIP { get; set; }
}
//
public class CustomValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if(null == userName || null == password)
{
throw new ArgumentNullException();
}
if(userName == "Oguz" && password == "2009")
{
return;
}
FaultCode fc = new FaultCode("ValidationFailed");
FaultReason fr = new FaultReason("Good reason");
throw new FaultException(fr,fc);
}
}
//
public class WmsStatService : IWmsStat, IPolicyProvider
{
public string sayHello(string name)
{
return "hello there " + name + " nice to meet you!";
}
public Stream ProvidePolicy()
{
WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
return new MemoryStream(File.ReadAllBytes("ClientAccessPolicy.xml"), false);
}
public string getConnectedViewers(string channelname)
{
// do stuff
return null;
}
}
}
app.config. 이 설정 파일이 작동하지 않습니다. 엔드 포인트에 대한 사용자 정의 인증을 넣기를 원했습니다. 나는 단서가 없다.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WindowsFormsApplication11.WmsStatService" behaviorConfiguration="mex">
<host>
<baseAddresses>
<add baseAddress="http://192.168.0.199:87" />
</baseAddresses>
</host>
<endpoint address="http://192.168.0.199:87/Test" binding="basicHttpBinding" bindingConfiguration="" contract="WindowsFormsApplication11.IWmsStat" behaviorConfiguration="MyServiceBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<!--<bindings>
<wsHttpBinding>
<binding name="wshttp">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>-->
<behaviors>
<serviceBehaviors>
<behavior name="mex">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
</behavior>
<behavior name="MyServiceBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WindowsFormsApplication11.CustomValidator, CustomValidator" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
젠장, 저이 지금 :( 파일이나 어셈블리 '직접 CustomValidator'또는 해당 종속성 중 하나를로드 할 수 없습니다 무엇입니까 지정한 파일을 찾을 수 없습니다 – Shift
을 그 오류는 여기이 설정에서 온다 userNamePasswordValidationMode = "사용자 지정"customUserNamePasswordValidatorType = "WindowsFormsApplication11.CustomValidator, 직접 CustomValidator"/> serviceCredentials> 은 서비스? –
를 실행할 때 사용 가능한 "직접 CustomValidator"조립 내가 WindowsFormsAppiication11에.이 자체가 WCF를 호스팅하는 것으로 변경인가요 Windows Forms에서 서비스. 내가 그 오류가 사라 졌다고하지만 다른 문제는 사라 졌다고 변경 한 후 : ( 'http://192.168.0.199:87/Test'(계약서가있는 "IWmsStat")의 ChannelDispatcher가 IChannelListener를 열 수 없습니다. – Shift