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)
它应该像下面这样简单:
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)
基本上,交换BasicHttpBinding为WsHttpBinding.
添加信息
摘自这个答案:
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 预发行版。
| 归档时间: |
|
| 查看次数: |
5481 次 |
| 最近记录: |