简体   繁体   中英

How to access a Web Service hosted on a Windows Service from a client application?

Recently I developed a WCF Web Service and, with the help of internet files, I managed to host it inside a Windows Service. I also managed to successfully install and start this Windows Service on my computer. In principle, the Web Service is working perfectly fine (debug was done); it's mission is to retrieve some data from a MySQL database located on the same computer.

Now my question is: suppose I'm on my product's client side; so now I want to develop a client application that enters in contact (to use) with my Web Service that is hosted on this Windows Service. How should I do this? What would be the necessary configurations/procedures in order for my application to locate the web service?

Notice that, for debug purposes, I managed to create a console debug application that successfully accessed the web service. This was done by the "add reference" menu at Visual Studio 2012 with the temporary link learned when debugging the WCF web service on its own - closed to figure 5-19 here . The WCF WS was found as part of the studio in which my test application was included by using the URL provided by VS

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

. Now that the WCF WS is located inside the Windows Service, I don't know which url to use.

Here is my current Windows Service App.config file:

<?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>

Note: on the code above, there is reference for another Web Service, namely a ASP.NET version of the WCF Web Service I developed.

Thanks for any help,

Momergil

--- EDIT --- I recently managed to edit my client application and execute it in another computer (with the same base system as mine). I got, then, this exception:

控制台应用程序显示异常错误

The Portuguese line tells: "No connection could be established because the destine machine actively refused them 127.0.0.1:12415.

我认为它应该是{baseAddress} / {endpoint name},因此对于第一个端点(wsHttpBinding),其http://127.0.0.1:12415/Lifemed/ ;对于Mex,它应该是http://127.0.0.1:12415/Lifemed/mex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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