小编Blu*_*Sky的帖子

DateTimeOffset的WCF服务参考?不使用FCL类型

我使用.NET 4.5.1作为我的WCF服务,使用.NET 4.0作为客户端Windows服务应用程序.

在数据协定中,有一个类型的DataMember DateTimeOffset?(可空DataTimeOffset).

当我向WCF服务添加服务引用时,它认为这DateTimeOffset?是一个复杂的类型.换句话说,它不认为它是一个System.DateTimeOffset?,它认为它是一个ServiceReference1.DateTimeOffset?

我该如何解决?

这是我到目前为止所尝试的:

  1. 创建演示此功能的最简单的示例解决方案.不幸的是我无法重新创建问题,因此它必须是我的配置中独有的东西.

  2. DataContract[KnownType(typeof(DateTimeOffset?))].注释类.不幸的是,这没有做任何事.

  3. 选中"在引用的程序集中重用类型".这导致"ServiceReference1"对象在控制台应用程序中完全不可用.

任何人都有任何其他想法如何解决这个问题?

谢谢.

.net c# wcf

12
推荐指数
1
解决办法
730
查看次数

Azure AD异常 - AADSTS50105 - "已登录的用户未分配给应用程序的角色"

我正在使用Azure AD为ASP.NET Web API 2 REST API设置身份验证.我希望所有客户都能够使用用户名和密码来验证REST API.我设置Azure的AD(低于满的步骤,但基本上是 - 创建一个目录,添加用户,添加的应用程序,在清单中,分配的用户添加的角色传递到应用程序).但是,当我尝试通过控制台应用程序(底部的完整代码)进行测试时,我得到了异常:

Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceExceptionMicrosoft.IdentityModel.Clients.ActiveDirectory.dll中发生了未处理的类型' ' 异常

其他信息:AADSTS50105:已登录的用户'test@azureadwebapitest.onmicrosoft.com'未分配给应用程序'8ed6bbe9-dce7-4bed-83af-aa5472ac4eef'的角色.

在此输入图像描述

我猜测需要在Manifest中调整一些东西,但我不知道.

这是代码:

using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;

namespace WebApiClientTest
{
    class Program
    {
        static void Main(string[] args)
        {
            const string authorityUri = "https://login.microsoftonline.com/azureadwebapitest.onmicrosoft.com/";
            const string resource = "https://azureadwebapitest.onmicrosoft.com/test";
            const string clientId = "8ed6bbe9-dce7-4bed-83af-aa5472ac4eef";
            const string userId = "test@azureadwebapitest.onmicrosoft.com";
            const string password = "[REMOVED for StackOverflow post]";

            UserCredential credentials = new UserCredential(userId, password);
            AuthenticationContext context = new AuthenticationContext(authorityUri);
            var authresult = context.AcquireToken(resource, clientId, credentials);
            Console.WriteLine("Access token: {0}", …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-active-directory

10
推荐指数
1
解决办法
2万
查看次数

如何将当前年份添加到Go模板?

在Go模板中,您可以检索如下字段:

template.Parse("<html><body>{{ .Title }}</body></html>")
template.Execute(w, myObject)
Run Code Online (Sandbox Code Playgroud)

您如何"内联"当前的UTC年份?我想做这样的事情:

template.Parse("<html><body>The current year is {{time.Time.Now().UTC().Year()}}</body></html>")
Run Code Online (Sandbox Code Playgroud)

但它返回错误:

恐慌:模板:功能"时间"未定义

go go-templates

6
推荐指数
1
解决办法
2472
查看次数

如何异步在ASP.NET 4.5 WebForms中执行两个同时进行的I/O绑定任务?

如何异步执行以下两种方法(StoreInSql,StoreInOtherDatabase),然后在设置标签输出消息之前等待两个结果都返回?可以使用await关键字干净地完成吗?非常感谢你.

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.RetryPolicies;
using Microsoft.WindowsAzure.Storage.Table;
using System;
using System.Web.UI;

namespace UpdateStorage
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string email = "test@test.com";

            // It takes approximately 300 ms to store in SQL Azure
            bool sqlStorageSuccessful = MyAppStorage.StoreInSqlAzureViaEF(email);

            // It takes approximately 300 ms to store in Azure Table Storage
            bool otherdbStorageSuccessful = MyAppStorage.StoreInAzureTableStorage(email);

            if (sqlStorageSuccessful && otherdbStorageSuccessful)
            {
                labelOutputMessage.Text = "Successfully stored the email.";
            }
            else
            {
                labelOutputMessage.Text = "We …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asynchronous async-await .net-4.5

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

Go 中的错误解析时间,微秒数可变

我正在尝试将字符串解析为时间对象。问题是微秒项中的位数发生了变化,这会破坏解析。例如,这工作正常:

package main

import (
    "fmt"
    "time"
)

func main() {
    timeText := "2017-03-25T10:01:02.1234567Z"
    layout := "2006-01-02T15:04:05.0000000Z"
    t, _ := time.Parse(layout, timeText)
    fmt.Println(t)
}
Run Code Online (Sandbox Code Playgroud)

但这会导致错误,因为微秒位数与布局不匹配:

package main

import (
    "fmt"
    "time"
)

func main() {
    timeText := "2017-03-25T10:01:02.123Z" // notice only 3 microseconds digits here
    layout := "2006-01-02T15:04:05.0000000Z"
    t, _ := time.Parse(layout, timeText)
    fmt.Println(t)
}
Run Code Online (Sandbox Code Playgroud)

我如何解决这个问题,以便仍然解析微秒项,但有多少位数字并不重要?

go

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