繁体   English   中英

从app.config将WCF服务客户端设置导入代码结构

[英]Import WCF service client settings from app.config into code structure

我已经写了一个Hello World WCF Web服务。 下面是使用该服务的客户端应用程序的我的App.config文件。 我希望所有这些数据都在客户端应用程序的代码中进行设置。 我怎样才能做到这一点? 我想编写一个类,封装所有需要在代码中设置的属性和方法。 我已经捕获了几乎所有的Endpoint和Binding属性,但是我在Contract设置上遇到了一些困难。 我很想知道是否有人能够在没有配置文件的情况下使它工作。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IHelloWorldService" allowCookies="true"
             maxReceivedMessageSize="20000000" maxBufferSize="20000000"                         maxBufferPoolSize="20000000">
        <readerQuotas maxDepth="32"
                maxArrayLength="200000000"
                maxStringContentLength="200000000"/>
      <security mode="None">
        <transport clientCredentialType="None" />
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>

 <endpoint address="http://localhost/HelloWorldService.svc"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHelloWorldService"
      contract="HelloWordServiceReference.IHelloWorldService"
      name="BasicHttpBinding_IHelloWorldService" />

</client>
</system.serviceModel>

</configuration>

如果您想添加所有客户端属性,服务类,则wcf服务附带了一些服务代理。 因此,当您创建wcf服务(自托管或Web服务器)并通过url Visual Studio添加服务引用时会发生什么,将自动生成代理类,其中包含从客户端使用Web服务所需的一切。 但是,如果您想手动创建客户端代理,则可以遵循以下URL: http://msdn.microsoft.com/zh-cn/library/ms734691(v= vs.110) .aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM