WCF .NET核心 - WsHttpBinding配置project.json
问题描述:
如何使用.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);
答
它应该是简单,如下:
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,交换BasicHttpBinding
为WsHttpBinding
。
添加的信息
从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预发布。
Tim,感谢您的回复。我无法在同一个SystemModel程序集中解析WsHtppBinding –
@AnandPatel - 你是指'WsHttpBinding'还是'WsHtppBinding'?它应该是'WsHttpBinding'按照我的例子(两个“t”,而不是两个“p”)。 – Tim
对不起。是WsHttpBinding –