![](/img/trans.png)
[英]How to access client application from web application with service application
[英]How to access a Web Service hosted on a Windows Service from a client application?
最近,我開發了WCF Web服務,並在Internet文件的幫助下設法將其托管在Windows Service中。 我還設法在計算機上成功安裝並啟動了Windows服務。 原則上,Web服務運行良好(調試已完成)。 它的任務是從位於同一台計算機上的MySQL數據庫檢索一些數據。
現在我的問題是:假設我在產品的客戶端; 所以現在我想開發一個客戶端應用程序,該應用程序可以與該Windows服務上托管的Web服務建立聯系(以使用)。 我應該怎么做? 為了使我的應用程序找到Web服務,需要哪些必要的配置/過程?
請注意,出於調試目的,我設法創建了一個控制台調試應用程序,該應用程序成功訪問了Web服務。 這是通過Visual Studio 2012上的“添加引用”菜單完成的,該菜單具有在自行調試WCF Web服務時所學到的臨時鏈接- 此處封閉於圖5-19。 WCF WS是使用VS提供的URL的工作室的一部分,其中包含我的測試應用程序
(http://127.0.0.1:12415/LifeWS.svc)
。 現在,WCF WS位於Windows Service內部,我不知道要使用哪個URL。
這是我當前的Windows Service 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服務的參考,即我開發的WCF Web服務的ASP.NET版本。
謝謝你的幫助,
莫吉爾
---編輯---我最近設法編輯了客戶端應用程序,並在另一台計算機(與我的基本系統具有相同的基本系統)上執行它。 然后,我得到了這個例外:
葡萄牙語行告訴我們:“無法建立連接,因為目標計算機主動拒絕了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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.