如何在Windows通用应用程序中使用双工合同来使用wcf服务?
我PlatformNotSupportedExcetpion: Operation is not supported on this platform.试图在Windows Universal App中使用双面wcf服务时遇到运行时异常,目标是Windows 10(10.0; Build 10240)
根据msdn,它支持API.
如果不可能,我应该如何进行我的方案?我有两个应用程序(控制台和Windows通用xaml应用程序)在同一台机器上运行,我需要双向通信.
我有创建服务主机的clasic .net 4.6控制台应用程序:
var host = new ServiceHost(typeof(MyService), new Uri("net.tcp://localhost:8008/MyService"));
var binding = new NetTcpBinding(); //I've also tried net http binding
binding.Security.Mode = SecurityMode.None;
host.Description.Behaviors.Add(new ServiceMetadataBehavior());
host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
MetadataExchangeBindings.CreateMexTcpBinding(),
"mex");
host.AddServiceEndpoint(typeof(IMyService), binding, "");
host.Open();
Run Code Online (Sandbox Code Playgroud)
服务合约:
[ServiceContract(CallbackContract = typeof(IMyServiceCallback))]
public interface IMyService
{
[OperationContract(IsOneWay = true)]
void Initialize();
}
public interface IMyServiceCallback
{
[OperationContract(IsOneWay = true)]
void OnFrame(int i);
}
Run Code Online (Sandbox Code Playgroud)
我曾尝试两者的ChannelFactory并通过添加服务引用对话框,既WCF客户端生成NetHttpBinding …
我已经使用Scaffold-DbContext从现有数据库生成了DbContext。
它使用Fluent映射API。是否可以对实体进行脚手架,以便为它们添加映射属性,例如:
[Table("People")]
public class Person
{
[Column("ID")]
public int Id {get; set;}
}
Run Code Online (Sandbox Code Playgroud) 当我使用 npm 安装打字稿定义时,我可以在作为 Visual Studio 构建一部分的打字稿文件中使用它们:
npm install @types/jQuery<TypeScriptCompile Include="wwwroot\js\site.ts" />到 .csproj。$在打字稿文件中使用全局变量但是,当我使用 libman 下载打字稿定义时,我在配置打字稿构建以使用它们时遇到了麻烦。
我想我需要添加 tsconfig.json,但它似乎干扰了 csproj 中的 TypeScriptCompile。
wwwroot
js
site.d.ts
site.ts
lib
jquery
jquery.min.js
@types
jquery
index.d.ts
misc.d.ts
…
MyProject.csproj
libman.json
Run Code Online (Sandbox Code Playgroud)
如何修改项目(.csproj、tsconfig.json),以便使用 wwwroot\lib\@types 而不是 node_modules/@types 中的定义文件和全局变量?
我已经创建了 tsconfig.json 并设置
"compilerOptions": {
"typeRoots": [ "wwwroot/lib/@types" ]
}
Run Code Online (Sandbox Code Playgroud)
但现在构建会在 site.ts 中返回诸如“找不到名称 MyInterface”之类的错误。MyInterface 在 site.d.ts 中定义。为什么在没有 tsconfig.json 时可以识别类型,而现在不能识别?我想避免添加///<reference> …
当我使用自定义ngDoBootstrap函数而不是默认函数时bootstrap: [AppComponent],如下所示:
@NgModule({
imports: [ BrowserModule, FormsModule, AppRoutingModule ],
declarations: [ AppComponent, HelloComponent ],
exports: [ AppComponent ],
entryComponents: [ AppComponent ],
// bootstrap: [AppComponent],
})
export class AppModule {
constructor(private injector: Injector) {
}
public ngDoBootstrap(): any {
const appElement = createCustomElement(AppComponent, { injector: this.injector });
customElements.define('my-app', appElement);
}
}
Run Code Online (Sandbox Code Playgroud)
然后 应用程序路由被破坏。
它会忽略 URL 中的任何更改,并且仅在我单击 时才起作用 <a [routerLink]='...'>。此外,初始路线 / 未加载。
它一定是由自定义引导机制引起的,因为当我取消注释时bootstrap: [AppComponent],一切正常。
完整代码可在此处获取:stackblitz 示例(由于 stackblitz 使用的 typescript 版本,需要下载并在本地运行)
如何使路由与自定义应用程序模块引导一起工作?
在带有 ASP.NET Core 后端的 SPA 中,我想创建用于上传将存储在本地托管的 Sharepoint 2016 中的文件的 UI。
我正要使用 C# CSOM,但它仅适用于 .NET Framework,不适用于 .NET 6。
我会使用 REST API,但我找不到任何有关如何获取身份验证令牌的示例。我的 Sharepoint 网站用户基于表单的身份验证(用户名/密码)。
我正在尝试将XML发布到asp.net核心2:
$.ajax({
type: "POST",
url: 'api/Test',
data: "<test>hello<test>",
contentType: "application/xml",
success: function (response) { alert(response); },
});
Run Code Online (Sandbox Code Playgroud)
我应该如何编写动作,使其接受xml作为参数?
IActionResult Post([FromBody]string xml) -> xml为空IActionResult Post([FromBody]XElement xml) -> xml为空IActionResult Post(XElement xml)-> InvalidOperationException:无法创建类型为'System.Xml.Linq.XElement'的实例。模型绑定的复杂类型不能为抽象或值类型,并且必须具有无参数构造函数。IActionResult Post(string xml) -> xml为空在Startup.ConfigureServices中:
services.AddMvc()
.AddXmlSerializerFormatters();
Run Code Online (Sandbox Code Playgroud)
如何编写控制器以使其接受XML作为参数?我知道我可以从HttpContext.Request中读取它,但是我希望它可以作为参数
我正在尝试自动化 SQL 部署,包括用户和角色。当我在 Sql Management Studio 中创建用户时它可以工作,但是当我部署 dacpack 时我得到 SqlException: Login Failed for user 'MyUser'
我在本地主机上安装了 SQL Server 2016,同时启用了 Sql Server 和 Windows 身份验证。
我在 Visual Studio 中有包含这些文件的 Sql 数据库项目:
MyUser.sql [构建操作=构建]
CREATE USER [MyUser] WITH Password='$(MyUserPassword)';
Run Code Online (Sandbox Code Playgroud)RolesMembership.sql [构建动作=构建]
ALTER ROLE [db_datareader] ADD MEMBER [MyUser]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [MyUser]
Run Code Online (Sandbox Code Playgroud)我构建它并使用命令行部署创建的 dacpac:
SqlPackage.exe /Action:Publish
/SourceFile:"MyDatabase.dacpac"
/Profile:"MyDatabase.publish.xml"
/v:MyUserPassword=c2Aaaaaaaaaaaa`
Run Code Online (Sandbox Code Playgroud)当我在 sql management studio 中执行此脚本时,它会起作用。但是当我使用 SqlPackage 部署它时,它会导致
SqlException: 用户“MyUser”登录失败
编辑:
我调查了生成的 sql 脚本,其中包括REVOKE CONNECT:
CREATE USER [MyUser] …Run Code Online (Sandbox Code Playgroud) sql-server database-project dacpac sqlpackage sql-server-2016
我正在使用 webclient 从 sharepoint 在线下载 XML 文件。
但是,当我使用WebClient.DownloadString(string url)方法时,某些字符未正确解码。
当我使用WebClient.DownloadFile(string url, string file)然后读取文件时,所有字符都是正确的。
xml 本身不包含编码声明。
string wrongXml = webClient.DownloadString(url);
//wrongXml contains Ä™ instead of ?
webClient.DownloadFile(url, @"C:\temp\file1.xml");
string correctXml = File.ReadAllText(@"C:\temp\file1.xml");
//contains ?, like it should.
Run Code Online (Sandbox Code Playgroud)
此外,当在 Internet Explorer 中打开 url 时,它会正确显示。
这是为什么?是因为我的机器上的默认 Windows 编码或 web 客户端在使用 DownloadString 或 DownloadFile 时处理响应的方式不同吗?
我正在使用EF Core 2.1预览本应该减少N + 1查询问题.我正在尝试进行查询,选择论坛帖子与帖子的作者:
dbContext.ForumThreads
.Include(t => t.Posts)
.Take(n)
.Select(t => new
{
t.Id,
t.Title,
PostAuhtors = t.Posts.Select(p => p.Author).Take(5)
}).ToArray();
Run Code Online (Sandbox Code Playgroud)
这会生成n + 1个查询:对于每个ForumThread,它会选择帖子作者
架构很简单:
public class ForumThread
{
public Guid Id {get;set;}
public string Title {get;set;}
public ICollection<ForumPost> Posts {get;set;}
}
public class ForumPost
{
public Guid Id {get;set;}
public string Author {get;set;}
public string Content {get;set;}
}
Run Code Online (Sandbox Code Playgroud) 我有两个网络核心控制台应用程序,我使用visual studio作为Web作业部署到Azure.
<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">
Run Code Online (Sandbox Code Playgroud)
当我单独发布它时,它运行良好.
我试过创造webproject/properties/webjob-list.json.路径与webproject/webproject.csproj相关:
{
"$schema": "http://schemastore.org/schemas/json/webjobs-list.json",
"WebJobs": [
{
"filePath": "../PeopleWebJob/PeopleWebJob.csproj"
},
{
"filePath": "../Reminder/ReminderWebJob.csproj"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我也试过安装Microsoft.Web.WebJobs.Publishnuget,但看起来这种方法不适用于.NET Core.
Alternativelly,
我试过dotnet publishWebJob项目并将输出复制到$(Build.ArtifactStagingDirectory)/webproject.zip/App_Data/jobs/Triggered
azure-web-sites azure-webjobs azure-devops asp.net-core asp.net-core-2.0
c# ×4
asp.net-core ×3
sql-server ×2
typescript ×2
.net ×1
.net-6.0 ×1
ajax ×1
angular ×1
angular8 ×1
azure-devops ×1
csom ×1
dacpac ×1
libman ×1
sharepoint ×1
sqlpackage ×1
uwp ×1
wcf ×1
webclient ×1
windows-10 ×1
xml ×1