如何使用引导令牌正确连接到 WCF 服务

发布于 2024-11-26 13:25:13 字数 1814 浏览 0 评论 0原文

我找不到我做错了什么。

当我尝试调用服务操作时,出现错误:

通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为它处于“故障”状态。

    using (Ref.SService_V1_0Client client = new Ref.SService_V1_0Client("RWS"))
{
    var request = new Ref.IVISRequestStructure();
    request.Header = new Ref.RequestHeaderStructure();


    client.ChannelFactory.Credentials.SupportInteractive = false;
    ChannelFactoryOperations.ConfigureChannelFactory(client.ChannelFactory);
    ChannelFactoryOperations.CreateChannelWithIssuedToken<Ref.ISService_V1_0>(client.ChannelFactory, ((Microsoft.IdentityModel.Claims.ClaimsIdentity)(Page.User.Identity)).BootstrapToken);
    client.StartTransaction("string argument");
}

web.config 中的配置:

 <system.serviceModel>
  <bindings>
    <ws2007FederationHttpBinding>
      <binding name="ws2007FederationUserName" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" maxReceivedMessageSize="100000000">
        <security mode="TransportWithMessageCredential">
          <message issuedKeyType="SymmetricKey" negotiateServiceCredential="true">
            <issuer address="adress/STS/Issue.svc/trust/13/issuedtokenmixedsymmetricbasic256" binding="customBinding" bindingConfiguration="issuedtokenmixedsymmetricbasic256"/>
          </message>
        </security>
      </binding>
    </ws2007FederationHttpBinding>
  </bindings>
  <client>
    <endpoint address="another_address/servicename.svc/ws2007Federation"
      binding="ws2007FederationHttpBinding" bindingConfiguration="ws2007FederationUserName"
      contract="Ref.ISService_V1_0" name="RWS" />
  </client>
 </system.serviceModel>

I cannot find what I`m doing wrong.

When I try to call service operation I get error:

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

    using (Ref.SService_V1_0Client client = new Ref.SService_V1_0Client("RWS"))
{
    var request = new Ref.IVISRequestStructure();
    request.Header = new Ref.RequestHeaderStructure();


    client.ChannelFactory.Credentials.SupportInteractive = false;
    ChannelFactoryOperations.ConfigureChannelFactory(client.ChannelFactory);
    ChannelFactoryOperations.CreateChannelWithIssuedToken<Ref.ISService_V1_0>(client.ChannelFactory, ((Microsoft.IdentityModel.Claims.ClaimsIdentity)(Page.User.Identity)).BootstrapToken);
    client.StartTransaction("string argument");
}

Configuration in web.config:

 <system.serviceModel>
  <bindings>
    <ws2007FederationHttpBinding>
      <binding name="ws2007FederationUserName" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" maxReceivedMessageSize="100000000">
        <security mode="TransportWithMessageCredential">
          <message issuedKeyType="SymmetricKey" negotiateServiceCredential="true">
            <issuer address="adress/STS/Issue.svc/trust/13/issuedtokenmixedsymmetricbasic256" binding="customBinding" bindingConfiguration="issuedtokenmixedsymmetricbasic256"/>
          </message>
        </security>
      </binding>
    </ws2007FederationHttpBinding>
  </bindings>
  <client>
    <endpoint address="another_address/servicename.svc/ws2007Federation"
      binding="ws2007FederationHttpBinding" bindingConfiguration="ws2007FederationUserName"
      contract="Ref.ISService_V1_0" name="RWS" />
  </client>
 </system.serviceModel>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北恋 2024-12-03 13:25:13

尝试使用 CreateChannelWithIssuedToken 调用的返回值来调用服务,而不是使用客户端变量。请参阅 本示例中的 CreateChannel 代码介绍了如何使用 CreateChannelWithIssuedToken。 代码如下所示:

var serviceClient = ChannelFactoryOperations.CreateChannelWithIssuedToken<Ref.ISService_V1_0>(client.ChannelFactory, ((Microsoft.IdentityModel.Claims.ClaimsIdentity)(Page.User.Identity)).BootstrapToken);
serviceClient.StartTransaction("string argument");

Try using the return value of the CreateChannelWithIssuedToken call to invoke the service instead of using the client variable. See the CreateChannel code in this sample for how CreateChannelWithIssuedToken is used. It would look like this:

var serviceClient = ChannelFactoryOperations.CreateChannelWithIssuedToken<Ref.ISService_V1_0>(client.ChannelFactory, ((Microsoft.IdentityModel.Claims.ClaimsIdentity)(Page.User.Identity)).BootstrapToken);
serviceClient.StartTransaction("string argument");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文