WCF .NET Core - WsHttpBinding Configuration project.json

杀马特。学长 韩版系。学妹 提交于 2019-12-01 17:39:39

问题


How do I configure wsHttpBinding with .NET core, Should I configure in Project.json file ? Before .NET Core the configuration is like below

<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>

I found an article which works looks like I am looking for but its BasicHttpBinding, I need 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);

回答1:


It should be as simple as the following:

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);

Baically, swap BasicHttpBinding for WsHttpBinding.

ADDED Information

Taken from this answer:

You need to add a reference to System.ServiceModel in your project.json, like this:

{
  "commands": {
      "run": "run"
  },
  "frameworks": {
      "dnx451": {
          "dependencies": {
              "Microsoft.AspNet.Mvc": "6.0.0-beta2"
          },
          "frameworkAssemblies": {
              "System.ServiceModel": "4.0.0.0"
          }
      }
  }
}

Note this answer was for ASP.NET 5 Pre-Release.



来源:https://stackoverflow.com/questions/38209824/wcf-net-core-wshttpbinding-configuration-project-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!