.net app.config的元素是什么?
app.config的元素是什么 为什么在我添加服务引用时会将其添加到客户端.net app.config的元素是什么?,.net,wcf,.net,Wcf,app.config的元素是什么 为什么在我添加服务引用时会将其添加到客户端 如何以编程方式访问此元素?它与WCF服务端的部分相对应。它主要用于配置用于将客户端和服务连接在一起的端点。换句话说,它指出了连接到服务的位置,以及使用哪个绑定 例如,如果您在IIS中托管了WCF服务,则可能会有如下部分: <system.serviceModel> <services> <service name="MyService"> <endpoi
如何以编程方式访问此元素?它与WCF服务端的部分相对应。它主要用于配置用于将客户端和服务连接在一起的端点。换句话说,它指出了连接到服务的位置,以及使用哪个绑定 例如,如果您在IIS中托管了WCF服务,则可能会有如下部分:
<system.serviceModel>
<services>
<service name="MyService">
<endpoint address="http://localhost:8080/MEX" binding="mexHttpBinding" bindingConfiguration="" name="mex" contract="IMetadataExchange" />
<endpoint address="http://localhost:8111" binding="wsHttpBinding" bindingConfiguration="WS_HTTP_Secure" name="WS_HTTP_Endpoint" contract="IMyService" />
</service>
</services>
</system.serviceModel>
MyServicesClient client = new MyServicesClient("WS_HTTP_Endpoint");
除非您有多个端点,否则不需要像这样在构造函数中实际指定它。通过向System.Configuration程序集添加引用,您还可以根据需要将节加载到内存中,并在那里检查它:
using System.Configuration;
using System.ServiceModel.Configuration;
.....
ClientSection clientSection =
(ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");
但通常,您只会使用Gavin Schultz描述的方法—让ServiceModel处理本节的阅读和解释,并为您提供一个用于调用服务的客户端代理
马克
using System.Configuration;
using System.ServiceModel.Configuration;
.....
ClientSection clientSection =
(ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");