【问题标题】:How to access a Web Service hosted on a Windows Service from a client application?如何从客户端应用程序访问托管在 Windows 服务上的 Web 服务?
【发布时间】:2014-02-11 10:45:24
【问题描述】:

最近我开发了一个 WCF Web 服务,在 Internet 文件的帮助下,我设法将它托管在一个 Windows 服务中。我还设法在我的计算机上成功安装并启动了这个 Windows 服务。原则上,Web 服务运行良好(调试已完成);它的任务是从位于同一台计算机上的 MySQL 数据库中检索一些数据。

现在我的问题是:假设我在产品的客户端;所以现在我想开发一个客户端应用程序,它可以与我的 Web 服务联系(使用),该 Web 服务托管在这个 Windows 服务上。 我该怎么做?为了让我的应用程序找到 Web 服务,需要哪些配置/程序?

请注意,出于调试目的,我设法创建了一个成功访问 Web 服务的控制台调试应用程序。这是通过 Visual Studio 2012 中的“添加引用”菜单完成的,其中包含在自行调试 WCF Web 服务时学习到的临时链接 - 关闭到图 5-19 here。 WCF WS 被发现是工作室的一部分,我的测试应用程序通过使用 VS 提供的 URL 包含在其中

(http://127.0.0.1:12415/LifeWS.svc)

。现在 WCF WS 位于 Windows 服务内部,我不知道该使用哪个 url。

这是我当前的 Windows 服务 App.config 文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="LifeWSService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="LifeWSBehavior" name="Lifemed.Service.LifeWSService"> <!--LifeWSService.LifeWSService-->
        <!-- this endpoint is exposed at the base address provided by host: http://localhost:12415/Lifemed  -->
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="LifeWSService.ILifeWS" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://127.0.0.1:12415/Lifemed" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="LifeWSBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <applicationSettings>
    <LifeWSService.Properties.Settings>
      <setting name="LifeWSService_LifeServices_LifeWS" serializeAs="String">
        <value>http://127.0.0.1:1559/LifeWS.asmx</value>
      </setting>
      <setting name="LifeWSService_LifeServices_WCF_LifeWS" serializeAs="String">
        <value>http://127.0.0.1:12415/LifeWS.svc</value>
      </setting>
    </LifeWSService.Properties.Settings>
  </applicationSettings>
</configuration>

注意:在上面的代码中,有另一个Web Service的引用,即我开发的WCF Web Service的ASP.NET版本。

感谢您的帮助,

莫默吉尔

--- 编辑 --- 我最近设法编辑了我的客户端应用程序并在另一台计算机上执行它(与我的基本系统相同)。然后,我得到了这个例外:

葡萄牙语线路告诉:“无法建立连接,因为目标机器主动拒绝了他们 127.0.0.1:12415。

【问题讨论】:

    标签: c# wcf web-services visual-studio client


    【解决方案1】:

    我认为它应该是 {baseAddress}/{endpoint name} 所以对于第一个端点 (wsHttpBinding) 它是 http://127.0.0.1:12415/Lifemed/ 而对于 Mex 它应该是 http://127.0.0.1:12415/Lifemed/mex

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 2011-07-08
      • 2016-09-30
      • 2011-10-09
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      相关资源
      最近更新 更多