.NET-在没有app.config的情况下部署WCF客户端 [英] .NET - deploying a WCF client, without an app.config

查看:145
本文介绍了.NET-在没有app.config的情况下部署WCF客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为WCF服务编写客户端。这是大型系统中的单个应用程序,其中包括用C#,C ++,VB和Java编写的模块。所有应用程序共享通用的配置和日志记录机制,而不管它们用什么语言编写。

I'm writing a client to a WCF service. This is a single app in a larger system that includes modules written in C#, C++, VB, and Java. All of the apps share common configuration and logging mechanisms, regardless of what language they were written in.

我想弄清楚如何构建客户端应用程序,以便它将在没有app.config的情况下运行。为什么?因为app.config中的大多数内容都是样板,所以不应允许sysadmins进行更改,并且应允许sysadmins进行哪些设置更改应在系统范围的配置中,而不是在app.config文件中

I'd like to figure out how to build the client application so that it will run without an app.config. Why? Because most of what is in the app.config is boilerplate that the sysadmins shouldn't be allowed to change, and what settings the sysadmins should be allowed to change should be in the system-wide configuration, and not in an app.config file sitting in the bin directory.

例子:客户端的app.config当前看起来像这样:

Case in point - the client's app.config currently looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="WSHttpBinding_ICourierService">
          <security defaultAlgorithmSuite="Default" authenticationMode="SecureConversation"
            ...
          </security>
          <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
            messageVersion="Default" writeEncoding="utf-8">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </textMessageEncoding>
          <httpTransport manualAddressing="false"
            ...
            useDefaultWebProxy="true" />
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:57102/MyService.svc"
        ...
        >
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

这是一堆不透明的样板,系统管理员不必处理。大部分是由Visual Studio插入的。我对该文件做了一个更改-我在< readerQuotas /> 中增加了最大大小。但这是我不希望系统管理员惹的祸。除了< endpoint address = = />

It's a bunch of opaque boilerplate that the sysadmins shouldn't have to deal with. Most of it was inserted by Visual Studio. I've made one change in the file - I increased the max size in <readerQuotas/>. But that's a change that I don't want the sysadmins to mess with. And there's nothing else in the file I want the sysadmins to mess with except for <endpoint address=""/>.

然后从系统范围的配置中提取端点地址,并在代码中进行设置。

And I'm pulling the endpoint address from the system-wide configuration, and setting it in code. There's nothing in this file that should be user-editable.

因此,我该如何配置事物以使我不需要显示它?

So, how do I configure things so that I don't need to have it present?

我可以将其作为资源嵌入到程序集中,并挂接到app.config加载过程中吗,就像我对所需DLL的处理方式一样?

Can I embed it as a resource in the assembly, and hook into the app.config load process, the way I do with required DLLs?

创建代码来配置事物的唯一选择是我使用代码设置端点地址的方式吗?在代码中创建必要的绑定等?那么,考虑到这些不透明的XML块,我如何知道要编写什么代码?

Is the only choice to create code to configure things, the way I'm using code to set the endpoint address? Create the necessary bindings, etc., in code? How, then, do I know what code to write, given these chunks of opaque XML?

推荐答案

您可以使用以下代码创建绑定,这是配置正在执行的操作。我不确定是否可以完全删除该文件,但是在这种情况下,应用程序将不会使用配置。将自己的值放在超时等中。

You can use the following code to creating the bindings which is what the config is doing. I am not sure whether that will let you remove the file altogether but the application won't use the config if this is the case. Put your own values in the timeouts, etc.

    var binding = new WSHttpBinding();
    binding.SendTimeout = new TimeSpan(0, 0, 0, 0, 100000);
    binding.OpenTimeout = new TimeSpan(0, 0, 0, 0, 100000);
    binding.MaxReceivedMessageSize = 10000;
    binding.ReaderQuotas.MaxStringContentLength = 10000;
    binding.ReaderQuotas.MaxDepth = 10000;
    binding.ReaderQuotas.MaxArrayLength = 10000;
    var endpoint = new EndpointAddress("http://localhost:57102/MyService.svc");
    var myClient = new WebServiceclient(binding, endpoint);

这篇关于.NET-在没有app.config的情况下部署WCF客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆