[英]WCF Service hosted in a WinForm is not working
I want to create a very simple WebService (WCF) inside a Winforms application. 我想在Winforms应用程序中创建一个非常简单的WebService(WCF)。 To test this I created a WCF Service called Calculator inside my Winforms application. 为了对此进行测试,我在Winforms应用程序中创建了一个称为计算器的WCF服务。 On the other side I created a simple Winforms application with a button to retrieve the Results of the service. 另一方面,我创建了一个带有按钮的简单Winforms应用程序,以检索服务的结果。
I have added the Webservice as a reference to the testproject. 我已将Web服务添加为对testproject的引用。 It recognizes the two implemented methods and everything just fine. 它识别出两种已实现的方法,一切都很好。 The problem is that I get no response from the webservice (freezing my testapplication). 问题是我没有从Web服务获得任何响应(冻结我的测试应用程序)。 I have most likely forgot something on the Webservice application. 我很可能忘记了Webservice应用程序上的某些内容。 What could it be? 会是什么呢?
Here's the 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
}
This is how I open the Webservice. 这就是我打开Web服务的方式。
this.m_WebService = new ServiceHost(typeof(Calculator));
this.m_WebService.Open();
Here is the App.config 这是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>
If I enter the URL ( http://localhost:8731/Solution/Calculator/
) in the Webbrowser I get this screen: 如果在Webbrowser中输入URL( http://localhost:8731/Solution/Calculator/
),则会显示以下屏幕:
With self hosting WCF services, the main Things to check are: 使用自托管WCF服务,要检查的主要内容是:
Try testing With the WCF Test Client. 尝试使用WCF测试客户端进行测试。 http://msdn.microsoft.com/en-us/library/bb552364(v=vs.110).aspx http://msdn.microsoft.com/zh-CN/library/bb552364(v=vs.110).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.