1
私はユーザ名/パスワードでwsHttpBinding
を設定しようとしています。 私が遭遇した問題は、ユーザー名/パスワードを設定する方法です。wsHttpBinding with username password
私は、この設定しました:
binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
をしかし、ここでユーザー名/パスワードの設定はありますか?
WSHttpBinding binding = new WSHttpBinding();
binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
Type contractType = typeof(ITest);
Type serviceType = typeof(Test);
Uri httpUri = new Uri("http://localhost:8083/Test2");
ServiceHost myServiceHost = new ServiceHost(serviceType, httpUri);
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
myServiceHost.Description.Behaviors.Add(smb);
myServiceHost.Open();
コード:WCFが認証にWindowsユーザーを使用してデフォルトで
namespace ConsoleApplication1
{
[ServiceContract]
interface ITest
{
[OperationContract]
string Ping();
}
}
namespace ConsoleApplication1
{
class Test : ITest
{
public string Ping()
{
return "Pong - it works!";
}
}
}
コードの前に何かを追加する必要がありますか?私は最初の行にnull参照例外を受け取ります。 – FrenkyB
基本的に問題は、これはnullです:myServiceHost.Description.Behaviors.Find()。 –
FrenkyB
次に、新しいServiceCredentialsビヘイビアをmyServiceHost.Description.Behaviorsに追加します。 –