我試着在Windows窗體應用程序中運行WCF服務。我複製並修改了Microsoft提供的WCF示例中的代碼。運行WCF Sample時,服務顯示在我使用的端口監視器(CurrPorts)中。當我運行我的代碼我看不到我的服務......Windows窗體應用程序中的WCF
這是我的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace NoName.Server
{
[ServiceContract(Namespace="http://NoName")]
public interface IApplicationService
{
[OperationContract()]
NoName.Entities.MediaParameter[] GetParametersForMediaObject(string mediaObjectId);
[OperationContract()]
NoName.Entities.MediaParameter GetMediaParameter(string parameterId);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NoName.Server
{
public class ApplicationService : IApplicationService
{
public Entities.MediaParameter[] GetParametersForMediaObject(string mediaObjectId)
{
throw new NotImplementedException();
}
public Entities.MediaParameter GetMediaParameter(string parameterId)
{
throw new NotImplementedException();
}
}
}
我從窗體運行它作爲
private void toolStripButton1_Click(object sender, EventArgs e)
{
using (ServiceHost host = new ServiceHost(typeof(ApplicationService)))
{
host.Open();
}
}
而且配置在app.config中:
<system.serviceModel>
<services>
<service name="NoName.Server.ApplicationService" behaviorConfiguration="ApplicationServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/NoName/ApplicationService"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/NoName/ApplicationService -->
<endpoint address="" binding="wsHttpBinding" contract="NoName.Server.IApplicationService"/>
<!-- the mex endpoint is exposed at soap.tcp://localhost:8000/NoName/ApplicationService/mex -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
<behaviors>
<serviceBehaviors>
<behavior name="ApplicationServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
它編譯沒有錯誤,當我運行它時沒有例外。它不會存在。想法?
你是什麼意思「它不會存在」?你看它在端口監視器佔用一個端口,所以它確實存在。 – kroonwijk