小编Hen*_*nry的帖子

使用从STS分配的令牌来调用WCF服务

我一整天都在盯着这一点无济于事,我没有想法.IP-STS处理登录,然后将其传递给RP-STS,RP-STS用声明填充令牌,然后到网站上.这工作正常.我在IP-STS上有一些WCF功能,例如更改密码/重置密码,需要访问它们.阅读后,我应该能够将已经分配的令牌发送到WCF,以确保用户通过身份验证.从我可以看到它发送令牌但不正确,也不是我想要的方式,因为它似乎需要一个用户名.

理想情况下,我希望它获取分配给用户的令牌,而不必重新请求或重新创建任何内容,并且绝对不需要用户名/密码.

我目前得到的错误是: 从另一方收到了一个不安全或不正确安全的故障.请参阅内部FaultException以获取故障代码和详细信息.

详细信息: 无法处理消息.这很可能是因为"http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue"操作不正确,或者因为邮件包含无效或过期的安全上下文令牌,或者因为存在不匹配绑定之间.如果服务由于不活动而中止了通道,则安全上下文令牌将无效.要防止服务中止空闲会话,请过早增加服务端点绑定的接收超时.

这是我的网络配置中的相关位.

客户端web.config


<system.serviceModel>
<bindings>
  <customBinding>
    <binding name="UsernameBinding">          <security authenticationMode="UserNameForCertificate"                  requireSecurityContextCancellation ="false"                  requireSignatureConfirmation="false"                  messageProtectionOrder ="SignBeforeEncryptAndEncryptSignature"                  requireDerivedKeys="true">
      </security>
      <httpTransport/>
    </binding>
  </customBinding>
  <wsFederationHttpBinding>
    <binding name="HTTPEndpoint" closeTimeout="00:10:00" openTimeout="00:10:00"
      receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false"
      transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
      textEncoding="utf-8" useDefaultWebProxy="true">
      <security mode="Message">
        <message issuedTokenType="http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1"   negotiateServiceCredential="false">              <claimTypeRequirements>

            <add claimType="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name" isOptional="false" />
          </claimTypeRequirements>

          <issuer address="http://localhost:13422/MembershipService" bindingConfiguration="UsernameBinding" binding="customBinding">
            <identity>
              <certificateReference findValue="STSTestCert" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="TrustedPeople" />
            </identity>
          </issuer>
        </message>

      </security>
    </binding>
  </wsFederationHttpBinding>
</bindings>

<behaviors>
  <!-- Credentials configuration -->
  <endpointBehaviors>
    <behavior name="ServiceBehavior"> …
Run Code Online (Sandbox Code Playgroud)

c# model-view-controller asp.net-mvc wcf wif

7
推荐指数
1
解决办法
4931
查看次数

使用MStest和moq测试TryUpdateModel()

我目前正在尝试测试使用TryUpdateModel()的插入方法.我正在伪装控制器上下文,这是必要的,虽然它的工作原理似乎并没有张贴我设置的模型.

这是我正在测试的方法:

 [AcceptVerbs(HttpVerbs.Post)]
    [GridAction]
    public ActionResult _SaveAjaxEditing(int? id)
    {
        if (id == null)
        {
            Product product = new Product();
            if (TryUpdateModel(product))
            {
                //The model is valid - insert the product.
                productsRepository.Insert(product);// AddToProducts(product);
            }
        }
        else
        {
            var recordToUpdate = productsRepository.Products.First(m => m.ProductID == id);
            TryUpdateModel(recordToUpdate);
        }
        productsRepository.Save();
        return View(new GridModel(productsRepository.Products.ToList()));
    }
Run Code Online (Sandbox Code Playgroud)

这是我目前的测试:

        [TestMethod]
    public void HomeControllerInsert_ValidProduct_CallsInsertForProducts()
    {
        //Arrange
        InitaliseRepository();

        var httpContext = CustomMockHelpers.FakeHttpContext();
        var context = new ControllerContext(new RequestContext(httpContext, new RouteData()), controller);
        controller.ControllerContext = context;
        //controller.ControllerContext = new ControllerContext();

        var …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc mstest moq

3
推荐指数
1
解决办法
880
查看次数

标签 统计

asp.net-mvc ×2

c# ×2

model-view-controller ×1

moq ×1

mstest ×1

wcf ×1

wif ×1