简体   繁体   English

从Azure ServiceConfig调用WCF服务

[英]Calling WCF service from Azure ServiceConfig

I added WCF Servicereference to my webapplication ,the following entries got created to my web.config . 我将WCF Servicereference添加到我的webapplication中,以下条目已创建到我的web.config中。

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_INameVerification" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="https://int. NameVerification.com/Default/NameVerificationService.svc"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_INameVerification"
    contract="NameVerificationService.INameVerification"
    name="WSHttpBinding_INameVerification" />
</client>

Now I am planning to host my application to Azure cloud platform. 现在我计划将我的应用程序托管到Azure云平台。 Once I host my app on cloud I want to be able to change my endpoints at any time ie., 一旦我在云上托管我的应用程序,我希望能够随时更改我的终端,即。

<endpoint address=”https://int. NameVerification.com/Default/NameVerificationService.svc” 
   binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_INameVerification"
    contract="NameVerificationService.INameVerification"
    name="WSHttpBinding_INameVerification" />

How do I add this call to my WCF service from SericeConfig ?What is the actual entriess in ServiceConfig so that my application will read my WCF end point address from Service config and not from web.config 如何从SericeConfig将此调用添加到我的WCF服务?ServiceConfig中的实际内容是什么,以便我的应用程序将从Service配置而不是web.config中读取我的WCF端点地址

Thank you all for your help . 谢谢大家的帮助 。

I found a solution for this problem. 我找到了解决这个问题的方法。

  1. Associated binding and serviceaddress in program, then added settings to Serviceconfig 程序中的关联绑定和serviceaddress,然后将设置添加到Serviceconfig
  2. ServiceConfig entry Added ServiceConfig条目已添加
 <Setting name="myServiceAddressUrl" value="https://int. NameVerification.com/Default/NameVerificationService.svc" /> 
    WSHttpBinding binding = new WSHttpBinding();
    binding.Name = "WSHttpBinding_INameServiceVerification";
    binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
    binding.ReliableSession.Enabled = false;
    binding.TransactionFlow = false;
    binding.Security.Mode = SecurityMode.Transport;
    binding.Security.Message.ClientCredentialType = 
        MessageCredentialType.Windows;

    string myServiceAddressUrl = 
        RoleEnvironmentWrapper.GetConfigurationSettingValue(
           "AdderssServiceURL.svc");
    EndpointAddress myService = new EndpointAddress(myServiceAddressUrl);

    NameVerificationClient verificationClient = 
        new NameVerificationClient(binding, myService );

Consider using startup task with console utility to read configuration from RoleEnvironment and manually (or by using ServiceManager) update your web.config. 考虑使用启动任务和控制台实用程序从RoleEnvironment读取配置并手动(或使用ServiceManager)更新web.config。 Another option would be to use Service Factory and read role configuration before explicit service creation. 另一种选择是在显式服务创建之前使用Service Factory并读取角色配置。

Probably it can be also accomplished by using WebRole OnStart method, but i'm not sure whether it is safe to modify web.config at this point 也许它也可以通过使用WebRole OnStart方法来完成,但我不确定此时是否可以安全地修改web.config

If I understand correctly, you're only looking to change endpoints of what service you consume without redeploying your service-consuming application that is running in Azure? 如果我理解正确,您只需要更改您使用的服务的端点,而无需重新部署在Azure中运行的服务消耗应用程序? You're not looking to change end-points of the actual service as it seems that this service is external to your solution? 您不希望更改实际服务的终点,因为此服务似乎是您的解决方案的外部服务?

If so, I'd like to suggest that you make your application not reliant on the endpoint configuration specified in the web.config file, but instead instrument your endpoint settings in ServiceConfig file (in whatever name-value pairs you feel are needed) and manually parse them when constructing a proxy to call your 3rd party endpoint. 如果是这样,我建议您使应用程序不依赖于web.config文件中指定的端点配置,而是在ServiceConfig文件中设置端点设置(无论您认为需要什么名称 - 值对)和在构建代理时手动解析它们以调用第三方端点。 This way you'll have complete control over what you're getting from web.config (perhaps binding configuration can still be driven by web.config) and what you're getting from ServiceConfig (the end-point UrL, etc) and are able to switch the endpoint later on in ServiceConfig w/o redeploying and/or taking down your application. 通过这种方式,您可以完全控制从web.config获得的内容(也许绑定配置仍然可以由web.config驱动)以及从ServiceConfig(终点UrL等)获得的内容能够在ServiceConfig中稍后切换端点,无需重新部署和/或关闭应用程序。

You will need to check RoleEnvironment if you're running under Azure (real or emulator) in order to read from ServiceConfig. 如果您在Azure(真实或模拟器)下运行以便从ServiceConfig中读取,则需要检查RoleEnvironment。

HTH HTH

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

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