本文介绍了有什么办法以编程方式设置HttpBinding吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
这是一个菜鸟问题:
我有一个使用网络服务的应用程序.为了摆脱app.config文件,我使用wsdl.exe生成了客户端类(而不是向项目添加服务引用).
有什么方法可以通过编程方式为这种客户端配置HttpBinding?
在此先感谢!
Hi all,
This is a rookie question:
I have an app that consumes a web service. In order to get rid of the app.config file I generated the client class using the wsdl.exe (instead of adding a service reference to the project).
Is there any way to programmatically configure the HttpBinding for this kind of client?
Thanks in advance!
推荐答案
ServiceHost host = new ServiceHost(typeof(MyService));
ContractDescription description = ContractDescription.GetContract(typeof(IMyService));
Binding binding = new WSHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost/MyService");
ServiceEndPoint endpoint = new ServiceEndpoint(description, binding, address);
host.Description.Endpoint.Add(endpoint);
host.Open();
祝你好运!
Good luck!
这篇关于有什么办法以编程方式设置HttpBinding吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!