c# - 从 C# 代码配置 Web 服务端点和契约(Contract)?

标签 c# web-services configuration

编辑:我决定将其转换为普通网页,因为我只需要提供一个整数参数并检索一个字符串。

如果有人有好的答案,我会留下这个问题。


我有一个我想调用的网络服务,但是因为它必须从一个插件调用到另一个系统,一个包含所有配置的应用程序配置文件不会做,因为插件系统不会读取它根本没有文件,只有 DLL。

所以,问题是,我怎样才能从配置文件中提取相关部分并将其转换为代码?

我可能需要转换的部分是:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="TooltipServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:2952/TooltipService.asmx"
            binding="basicHttpBinding" bindingConfiguration="TooltipServiceSoap"
            contract="TooltipService.TooltipServiceSoap" name="TooltipServiceSoap" />
    </client>
</system.serviceModel>

URL 等当然会改变,但这是为了让我弄清楚是否有人可以为我指出正确的方向,告诉我如何将必要的代码添加到应用程序中,这样如果我删除应用程序配置文件,它仍然有效。

最佳答案

我在 web.config 文件中使用以下配置通过 REST 服务上传超过 64 KB(默认)的文件。

<system.serviceModel>
    <services>
      <service name="Service">
        <endpoint
          address=""
          binding="webHttpBinding" bindingConfiguration="FileTransferServicesBinding"
          contract="IService"/>
      </service>
    </services>
    <bindings>
      <webHttpBinding >
        <binding name="FileTransferServicesBinding" maxBufferSize="10242880"  maxReceivedMessageSize="10242880">
          <readerQuotas maxStringContentLength="10242880"  maxArrayLength="10242880" />
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>


<system.web>
    <httpRuntime maxRequestLength="65536" executionTimeout="36000"/>
</System.Web>

关于c# - 从 C# 代码配置 Web 服务端点和契约(Contract)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/688988/

相关文章:

java - 如何构建 java web 服务并在 j2me 客户端中使用它(使用 netbeans)

c# - Web 服务无法序列化接口(interface)

java - 通过自动配置作为模块打开附加端口时,应用程序无法启动

configuration - Redis 复制配置

c# - IIS 上使用 Autofac 的 WebApi REST 服务,首次调用时出错

c# - 在 datagridview 的工具提示中显示图像

C# - 构造函数中的类型参数 - 无泛型

python - 如何使用生物服务在不指定生物体的情况下访问 KEGG 条目?

configuration - 没有.pc文件时,让Autoconf手动检查库

c# - java 和 Wp7 中的压缩和加密不匹配