Windows アプリケーション内でホストされている非常に単純な WCF サービスがあります。GETメソッドを使用してサービスにアクセスしようとしていますが、空のページを取得するだけです。設定に何か問題があると思いますが、何が原因かわかりませんでした。コードは次のとおりです。
WCFService.cs
namespace WCFServiceApp
{
[ServiceContract]
public class WCFService
{
[OperationContract]
[WebGet]
public int GetNumbers()
{
return 12345;
}
}
}
Form1.cs
private static Uri baseAddress = new Uri("http://localhost:8090");
private ServiceHost host = new ServiceHost(typeof(WCFService), baseAddress);
protected override void OnLoad(EventArgs e)
{
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.Open();
base.OnLoad(e);
}
App.config
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WCFServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="WCFService" behaviorConfiguration="WCFServiceBehavior">
<endpoint address="ws" binding="wsHttpBinding" contract="WCFService">
</endpoint>
<endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" contract="WCFService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
ブラウザでlocalhost:8090にアクセスすると、WCF ウェルカム ページが表示されます。localhost:8090/GetNumbersを押すと、数字の代わりに空のページが表示されます。