1
環境:Windows XP,Visual Studio 2010中,IIS 不安裝。WCF服務,在WCF SVC主機的工作,不工作作爲Windows服務
我已經開發了一個WCF服務作爲WCFSvcHost託管時工作正常庫;我可以連接到它,更新客戶的服務參考,作品。
我無法承載它作爲Windows服務,雖然。該服務安裝好,我可以附加到它並打破我的代碼。爲了調試主機,我將代碼移到了OnResume()(OnStart什麼都不做)。
這裏是我的onResume(名稱已更改爲保護無辜者):
protected override OnResume()
{
if (_selfHost == null)
{
_selfHost = new ServiceHost(typeof(MyService));
_selfHost.Open();
}
}
當通過Open()方法步進,我得到以下異常:
System.InvalidOperationException was unhandled by user code
Message=The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address. Either supply an http base address or set HttpGetUrl to an absolute address.
Source=System.ServiceModel
StackTrace:
at System.ServiceModel.Description.ServiceMetadataBehavior.EnsureGetDispatcher(ServiceHostBase host, ServiceMetadataExtension mex, Uri url, String scheme)
at System.ServiceModel.Description.ServiceMetadataBehavior.CreateHttpGetEndpoints(ServiceDescription description, ServiceHostBase host, ServiceMetadataExtension mex)
at System.ServiceModel.Description.ServiceMetadataBehavior.ApplyBehavior(ServiceDescription description, ServiceHostBase host)
at System.ServiceModel.Description.ServiceMetadataBehavior.System.ServiceModel.Description.IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase)
at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
at System.ServiceModel.ServiceHostBase.InitializeRuntime()
at System.ServiceModel.ServiceHostBase.OnBeginOpen()
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at MyService.StartService()
at MyService.OnContinue()
at System.ServiceProcess.ServiceBase.DeferredContinue()
InnerException:
沒有量改變我的配置文件似乎解決了這個問題:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="MyService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/MyService/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="MyLib.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://localhost:8732/MyService/mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
作爲一個測試,我試圖設置httpG etEnabled爲False,並刪除MEX終結點,但只有移到別處的問題:錯誤信息消失並啓動服務,但後來我的客戶端不能調用服務:
System.ServiceModel.EndpointNotFoundException was caught
Message=There was no endpoint listening at http://localhost:8732/MyService/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
[...]
InnerException: System.Net.WebException
Message=The remote server returned an error: (400) Bad Request.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
InnerException:
任何幫助嗎?
你有沒有嘗試在控制檯應用程序託管?不是爲了替代服務,而只是爲了確保它能夠工作? – 2012-02-20 22:45:59
另外 - 我會通過一個非常簡單的例子來得到一個WCF服務作爲一個Web服務來運行,看看這樣做是否有助於你看到你在做什麼不同。請參閱:http://msdn.microsoft.com/en-us/library/ms733069.aspx – 2012-02-20 22:48:00
特里:聰明的想法。我得到與Windows服務相同的錯誤。 – dlesage 2012-02-20 23:23:09