Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF .NET Core - WsHttpBinding Configuration project.json

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);
like image 576
Anand Patel Avatar asked Jul 05 '16 18:07

Anand Patel


1 Answers

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.

like image 89
Tim Avatar answered Sep 22 '22 00:09

Tim