WCF .NET Core-WsHttpBinding配置project.json

Ana*_*tel 5 wcf asp.net-core-1.0

如何使用.NET Core配置wsHttpBinding,是否应在Project.json文件中进行配置?在.NET Core之前的配置如下

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="IService_Endpoint">
      <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://serviceURL/Service.svc"
      binding="wsHttpBinding" bindingConfiguration="IService_Endpoint"
      contract="IService" name="IService_Endpoint" />
</client>
Run Code Online (Sandbox Code Playgroud)

我发现有一篇看起来不错的文章,但它的BasicHttpBinding需要wsHttpBinding。

ChannelFactory<IGetPeopleService> factory = null;  
IGetPeopleService serviceProxy = null;  
Binding binding = null;

binding = new BasicHttpBinding(BasicHttpSecurityMode.None);  
factory = new ChannelFactory<IGetPeopleService>(binding, new EndpointAddress("http://localhost/people.svc"));  
serviceProxy = factory.CreateChannel();

var result = serviceProxy.GetPeopleData(100);
Run Code Online (Sandbox Code Playgroud)

Tim*_*Tim 2

它应该像下面这样简单:

ChannelFactory<IGetPeopleService> factory = null;  
IGetPeopleService serviceProxy = null;  
Binding binding = null;

binding = new WsHttpBinding(SecurityMode.None);  
factory = new ChannelFactory<IGetPeopleService>(binding, new EndpointAddress("http://localhost/people.svc"));  
serviceProxy = factory.CreateChannel();

var result = serviceProxy.GetPeopleData(100);
Run Code Online (Sandbox Code Playgroud)

基本上,交换BasicHttpBindingWsHttpBinding.

添加信息

摘自这个答案

System.ServiceModel您需要在 project.json 中添加对的引用,如下所示:

{
  "commands": {
      "run": "run"
  },
  "frameworks": {
      "dnx451": {
          "dependencies": {
              "Microsoft.AspNet.Mvc": "6.0.0-beta2"
          },
          "frameworkAssemblies": {
              "System.ServiceModel": "4.0.0.0"
          }
      }
  }
}
Run Code Online (Sandbox Code Playgroud)

请注意,此答案适用于 ASP.NET 5 预发行版。

  • .NET core 的 System.ServiceModel 没有 WsHttpBidning (2认同)
  • @Tim 是的,但提出的问题是针对 .NET Core - 而不是 .NET Framework。 (2认同)