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