[英]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.