我遵循此(http://msdn.microsoft.com/en-us/library/ms733069.aspx)鏈接並創建了服務和服務主機。 我向解決方案添加了一個webform客戶端項目。爲了檢查我的服務是否收到請求,我在服務中添加了一個日誌。 我選擇了我的主機和客戶端,通過設置多個啓動項目同時運行。 但我有一個問題,使我的服務和客戶端之間的溝通。我缺少配置中的東西?我沒有看到異常(儘管我選擇了CLR和JSRuntime異常,並且提供了託管調試幫助)。託管在Windows服務託管的WCF服務
這裏是我的服務配置
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client/>
<behaviors>
<serviceBehaviors>
<behavior name="meta">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="InboundMessage.Service.Operator" behaviorConfiguration="meta" >
<endpoint address="basic" binding="basicHttpBinding" contract="InboundMessage.Service.IOperator" name="basic"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<!--<endpoint address="" binding="wsHttpBinding" contract="IMetadataExchange" name="Ws" />-->
<host>
<baseAddresses>
<add baseAddress = "http://IP/InboundMessage.Service/"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="InboundMessage.Service.Operator"/>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
服務主機:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="meta">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<diagnostics performanceCounters="ServiceOnly" />
<services>
<service name="InboundMessage.Service.Operator" behaviorConfiguration="meta">
<endpoint address="basic" binding="basicHttpBinding" contract="InboundMessage.Service.IOperator" name="basic"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<!--<endpoint address="" binding="wsHttpBinding" contract="IMetadataExchange" />-->
</service>
</services>
</system.serviceModel>
<system.web>
<compilation
debug="true" >
</compilation>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
一個windowform客戶端配置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.web>
<compilation debug="true"></compilation>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="meta" name="InboundMessage.Service.Operator">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://IP/InboundMessage.Service/"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="InboundMessage.Service.Operator"/>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="meta">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
編輯: 二手Tim的評論安裝服務,但我安裝時遇到問題。 我打開另一個問題,謝謝蒂姆我有問題在我的本地機器上安裝服務。我打開另一個問題:Unable to install service using sc command
感謝您的回覆。當你說「(在你的情況下,因爲你沒有設置除名稱以外的任何內容都不重要」,你能詳細說明你認爲我設置名稱的位置嗎?它是否在服務中?另一件事情,因爲我刪除了標籤客戶端是否需要刪除標籤? –
HXD
@HXD - 對不起,我在答案的這一部分並不十分清楚,我的意思是你在配置文件中定義了一個'basicHttpBinding'配置,命名爲「InboundMessage.Service.Operator」。您不會在端點中引用該綁定配置,因此不會使用它。由於您沒有爲「InboundMessage.Service.Operator」綁定配置指定任何值,因此無關緊要。例如,如果您指定了更大的郵件大小限制,那麼這很重要。是的,你也可以刪除''標籤。 –
Tim
謝謝蒂姆我有問題在我的本地機器上安裝服務。我打開另一個問題:http://stackoverflow.com/questions/22416910/unable-to-install-service-using-sc-command – HXD