環境:Windows XP、Visual Studio 2010、IIS がインストールされていません。WCFサービスで、WCF SvcホストでWindowsサービスとして動作しません。
私はWCFSvcHostでホストされているときにうまく動作するライブラリとしてWCFサービスを開発しました。私はそれに接続し、クライアントのサービス参照を更新することができます。
私はWindowsサービスとしてホストすることはできません。サービスは正常にインストールされ、私はそれに接続してコードを壊すことができます。ホスティングをデバッグするために、コードをOnResume()に移動しました(OnStartは何もしません)。ここで
は(名前は無実を保護するために変更されている)私のOnResumeです:protected override OnResume()
{
if (_selfHost == null)
{
_selfHost = new ServiceHost(typeof(MyService));
_selfHost.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 FalseにetEnabledと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:
任意の助けを?
コンソールアプリケーションでホスティングしてみましたか?サービスの代わりにではなく、機能することを確認するだけです。 –
また、Webサービスとして実行されているWCFサービスを取得し、それがあなたが何をしているのかを見分けることができるかどうかを確認するための非常に簡単な例を紹介します。参照してください:http://msdn.microsoft.com/en-us/library/ms733069.aspx –
テリー:スマートなアイデア。 Windowsサービスと同じエラーが表示されます。 – dlesage