[英]WCF Service hosted in a WinForm is not working
我想在Winforms應用程序中創建一個非常簡單的WebService(WCF)。 為了對此進行測試,我在Winforms應用程序中創建了一個稱為計算器的WCF服務。 另一方面,我創建了一個帶有按鈕的簡單Winforms應用程序,以檢索服務的結果。
我已將Web服務添加為對testproject的引用。 它識別出兩種已實現的方法,一切都很好。 問題是我沒有從Web服務獲得任何響應(凍結我的測試應用程序)。 我很可能忘記了Webservice應用程序上的某些內容。 會是什么呢?
這是網絡服務:
[ServiceContract] public interface ICalculator { [OperationContract] double AddNumbers(double number1, double number2); [OperationContract] string TestMethod();
}
public class Calculator : ICalculator
{
#region ICalculator Member
public double AddNumbers(double number1, double number2)
{
return number1 + number2;
}
public string TestMethod()
{
return "HELLO WORLD!";
}
#endregion
}
這就是我打開Web服務的方式。
this.m_WebService = new ServiceHost(typeof(Calculator));
this.m_WebService.Open();
這是App.config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Solution.Server.CalculatorBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Solution.Server.CalculatorBehavior"
name="Solution.Server.Calculator">
<endpoint address="" binding="wsHttpBinding" contract="Solution.Server.ICalculator">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Solution/Calculator/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
如果在Webbrowser中輸入URL( http://localhost:8731/Solution/Calculator/
),則會顯示以下屏幕:
使用自托管WCF服務,要檢查的主要內容是:
嘗試使用WCF測試客戶端進行測試。 http://msdn.microsoft.com/zh-CN/library/bb552364(v=vs.110).aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.