私の設定に何か問題があると思います。IIS でラップされたパスワードで保護されたセキュリティを取得しようとしています (まだ達成されていません)。あらゆる種類の例外が発生しています。今回は、セキュリティ トークンの無効または不正な形式の要素の例外が発生しています。ここに私の設定があります:
ホスト:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name ="WSHttpBinding_ISVC1">
<security mode="Message">
<message clientCredentialType="UserName" establishSecurityContext="false"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SVCBehaviors">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="blahblah.SVCValidator, TrademarkGlobal.Web"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="blahblah.SVC"
behaviorConfiguration="SVCBehaviors">
<endpoint address="" binding="wsHttpBinding"
contract="blahblah.ISVC" name="WSHttpBinding_ISVC1"/>
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding" address="mex"/>
</service>
</services>
</system.serviceModel>
</configuration>
CLIENT:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ISVC1">
<security mode="Message">
<message clientCredentialType="UserName" establishSecurityContext="false"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:64609/SVC.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ISVC1" contract="ISVC">
</endpoint>
</client>
</system.serviceModel>
SVC ファイル (svc.svc):
<%@ServiceHost Service="blahblah.SVC" %>
Service (SVC & ISVC) は、今のところ基本的な文字列を返すだけです。
SVCVALIDATOR.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using System.IdentityModel.Selectors;
public class SVCValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (userName == null || password == null)
{
throw new ArgumentNullException();
}
if (userName != "gooduser" && password != "goodpass")
{
throw new Exception("Incorrect Username or Password");
}
}
}
実行に使用されるコントローラーのアクション:
public class SVCController : Controller
{
public ActionResult Index(string user = "bad", string pass = "bad")
{
using (SVCClient client = new SVCClient())
{
//SVCClient client = new SVCClient("WSHttpBinding_ISVC");
client.ClientCredentials.UserName.UserName = user;
client.ClientCredentials.UserName.Password = pass;
ViewBag.Message = client.Test();
return View("RunningSVC");
}
}
}