0
我試圖建立一個測試應用程序來測試WCF和了解更多關於它:WCF與Windows服務託管,客戶端無法看到端點
我寫了一個WCF服務,並在一個窗口服務託管這一點。這裏是我的app.config
從Windows服務:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="WCFLibrary.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/ServiceModelSamples/service -->
<endpoint
address=""
binding="wsHttpBinding"
contract="WCFLibrary.ICalculator" />
<!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
現在我想建立一個客戶端應用程序消耗WCF服務。但是當我去Add Service Reference
它給我一個錯誤,它不能達到終點。我可以看到從服務管理器運行的服務。我通過從VS執行調試來做測試。在調試期間,客戶端能夠看到端點。但是,如果我停止並且調試返回到服務管理器,則客戶端無法看到端點。
什麼可能是錯的?請提供任何線索嗎?
EDIT1
Windows服務(Service1.cs
)
namespace WindowsService
{
public partial class Service1 : ServiceBase
{
public ServiceHost serviceHost = null;
public Service1()
{
InitializeComponent();
}
public void onDebug()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
}
// Create a ServiceHost for the CalculatorService type and
// provide the base address.
serviceHost = new ServiceHost(typeof(CalculatorService));
// Open the ServiceHostBase to create listeners and start
// listening for messages.
serviceHost.Open();
}
protected override void OnStop()
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost = null;
}
}
}
}
Program.cs
:
namespace WindowsService
{
public class CalculatorWindowsService :ServiceBase
{
public ServiceHost serviceHost = null;
public CalculatorWindowsService()
{
// Name the Windows Service
ServiceName = "WCFWindowsServiceSample";
}
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main()
{
//#if DEBUG
// Service1 myservice = new Service1();
// myservice.onDebug();
// System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
//#else
// CalculatorWindowsService calc = new CalculatorWindowsService();
ServiceBase.Run(new CalculatorWindowsService());
//#endif
}
}
}
在本地網絡瀏覽器中打開您的服務的URL以查看任何錯誤消息;檢查事件查看器以查看任何投訴;並檢查防火牆的入站和出站規則,以確定端口8000是否真正開放。 – ZZZ
@AndyH:在Internet Explorer中,它給了我'頁面無法顯示','http:// localhost:8000/ServiceModelSamples/service' – user726720
在事件查看器中,它向我顯示服務已經開始,如果我從服務管理器顯示服務已成功停止 – user726720