2016-07-05 63 views
2

如何使用.NET核心配置wsHttpBinding,我應該在Project.json文件中進行配置嗎? .NET的核心之前,配置是像下面WCF .NET核心 - WsHttpBinding配置project.json

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

我發現它的工作原理的文章看起來像我期待的,但它的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); 

回答

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

Baically,交換BasicHttpBindingWsHttpBinding

添加的信息

this answer摘自:

您需要參考您的project.json添加到System.ServiceModel,像這樣:

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

注意這個答案是對ASP .NET 5預發佈。

+0

Tim,感謝您的回覆。我無法在同一個SystemModel程序集中解析WsHtppBinding –

+0

@AnandPatel - 你是指'WsHttpBinding'還是'WsHtppBinding'?它應該是'WsHttpBinding'按照我的例子(兩個「t」,而不是兩個「p」)。 – Tim

+0

對不起。是WsHttpBinding –