WCFサービスの一部のエンドポイントを保護する必要があります。エンドポイントを保護できるかどうかはわかりません。私は以下のWCFサービス(自己ホスト)を持っています。同じWCFがCAポリシーファイルにも対応しています。このWCFサービスまたはいくつかのエンドポイントのセキュリティを確保した場合、CAポリシーパートはユーザー名パスワードを要求してはなりません。ポリシーファイルは常にアクセス可能でなければなりません。それも可能ですか?カスタム認証でWCFサービスエンドポイントを保護する
私は多くのWCFカスタムブログ/投稿を見つけました。セキュリティを行う方法はたくさんあります。私が望むのは、ユーザー名/パスワードでいくつかのエンドポイントを保護できるということですが、Fiddlerのようなツールでは資格情報を表示してはいけません。ただし、この場合はデータが表示されます。
私はすでに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」またはその依存関係の1つをロードできませんでした。システムは指定されたファイルを見つけることができませんくそ – Shift
エラーがここにこの設定から来ている:。。
を実行するとuserNamePasswordValidationMode = "カスタム" customUserNamePasswordValidatorType = "WindowsFormsApplication11.CustomValidator、のCustomValidator" /> serviceCredentials> は、私がWindowsFormsAppiication11に。これは、WCFホストされた自己であることに変更可能なこと "のCustomValidator" アセンブリです私はそれを変更した後、エラーは消えてしまったが、別の問題:( ChannelDispatcher 'http://192.168.0.199:87/Test' with contract(s) 'IWmsStat' 'がIChannelListenerを開くことができません – Shift