使用 Silverlight 客户端获取 WCF 服务声明时出现问题

发布于 2024-11-28 01:14:07 字数 1880 浏览 1 评论 0原文

我有一个 Silverlight 客户端应用程序,它登录到 STS 并获取一组声明作为回报。我使用 Identity Training Kit 附带的 Silverlight IdentityModel。这很好用。

问题是当我进行服务调用(用于获取一些数据)时,在服务中我可以看到 IClaimsIdentity 类型的身份,但其声明集合为空。使用 ClaimsIdentitySessionManager InvokeAsync 方法调用该服务,以便将 IssuedToken 信息添加到 SOAP 标头中。服务调用在会话管理器的上下文中执行。

我尝试了不同类型的代码和设置,但无法获得该服务的声明。我读过它应该通过使用 CustomBinding 来工作,但是在使用它时出现错误: Content Type text/xml;服务 不支持 charset=utf-8 。客户端和服务绑定可能不匹配

我什至尝试使用“TextMessageEncoding”而不是“BinaryMessageEncoding”来处理不同的消息版本,但这没有帮助。

这个错误是什么意思?我该如何解决这个问题?

用于调用 WCF 服务的代码:

private void GetWeekPlanning()
{
   var service = _ServiceManager.GetServiceDescriptionAndCheckNull(typeof(ILeisureServiceAsync), ServiceTransportType.BasicHttpBinding);

   var binding = new CustomBinding()
   {
      Elements = { new BinaryMessageEncodingBindingElement(), new HttpsTransportBindingElement() }
   };

   var proxy = new LeisureServiceAsyncProxy(binding, service.ServiceEndpointAddress);

   ClaimsIdentitySessionManager.Current.InvokeAsync(
      () =>
      {
         proxy.BeginGetActivityPlanListByDate(
            DateTime.MinValue,
            DateTime.MaxValue,
            result =>
            {
               var plans = proxy.EndGetActivityPlanListByDate(result);

               SynchronizationContext.Post(
                  callback =>
                  {                           
                     // Do something with plans
                  },
                  null);
            },
            null);
      },
    proxy.InnerChannel,
    WSTrust13Constants.KeyTypes.Bearer);
}

来自服务器 App.config 的代码片段: http://pastebin.com/7RmPQVUR

客户端 web.config: http://pastebin.com/Bz9W6mUj

亲切的问候,

汉斯

I have a Silverlight client application which logs on to an STS and gets a collection of claims in return. I use the Silverlight IdentityModel which came with the Identity Training Kit. This works fine.

The problem is when I do a service call (for getting some data), within the service I can see an identity of type IClaimsIdentity, but its claims collection is empty. The service is called by using the ClaimsIdentitySessionManager InvokeAsync method so the IssuedToken information is added to the SOAP header. The service call is executed within the context of the session manager.

I tried different kinds of code and settings, but I cannot get the claims to the service. I’ve read that it should work by using a CustomBinding, but when using it I get an error: Content Type text/xml; charset=utf-8 was not supported by service . The client and service bindings may be mismatched.

I even tried using ‘TextMessageEncoding’ instead of ‘BinaryMessageEncoding’ with different message versions, but it didn’t help.

What does this error mean and how can I solve this?

Code used to call WCF service:

private void GetWeekPlanning()
{
   var service = _ServiceManager.GetServiceDescriptionAndCheckNull(typeof(ILeisureServiceAsync), ServiceTransportType.BasicHttpBinding);

   var binding = new CustomBinding()
   {
      Elements = { new BinaryMessageEncodingBindingElement(), new HttpsTransportBindingElement() }
   };

   var proxy = new LeisureServiceAsyncProxy(binding, service.ServiceEndpointAddress);

   ClaimsIdentitySessionManager.Current.InvokeAsync(
      () =>
      {
         proxy.BeginGetActivityPlanListByDate(
            DateTime.MinValue,
            DateTime.MaxValue,
            result =>
            {
               var plans = proxy.EndGetActivityPlanListByDate(result);

               SynchronizationContext.Post(
                  callback =>
                  {                           
                     // Do something with plans
                  },
                  null);
            },
            null);
      },
    proxy.InnerChannel,
    WSTrust13Constants.KeyTypes.Bearer);
}

Code snippet from the server App.config: http://pastebin.com/7RmPQVUR

The client web.config: http://pastebin.com/Bz9W6mUj

Kind Regards,

Hans

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文