WCF Service(NetTcpBinding) + 托管 WPF 应用程序上的主机



我想创建一个带有 WCF 服务的 WPF 应用程序来侦听某个端口。我创建了 C# CLass 库(UfebsSignServiceLibrary)并添加到 WCF 服务中。在库中之后,我添加了接口和类实现器。 我创建了 WPF 应用程序,并希望在里面承载我的 WCF 服务。我在我的WPF APP,configuration app.config中添加了对UfebsSignServiceLibrary的引用。WPF 已启动,但是当我尝试在 WCF 服务上添加服务引用时,出现错误 - 元数据包含无法解析的引用。

我已经尝试启用"httpGetEnabled","httpsGetEnabled"并为http协议()添加了baseAddress。我阅读了许多关于同一问题的主题,但我没有找到适合我的情况的答案。

具有 WCF 服务代码的"我的类库":

namespace UfebsSignServiceLibrary
{
[ServiceContract]
public interface IUfebsSignService
{
[OperationContract]
byte[] SignData(byte[] data, string profileName);
}
namespace UfebsSignServiceLibrary
{
public class UfebsSignService : IUfebsSignService
{
public byte[] SignData(byte[] data, string profileName)
{
// Some Code
}
}

我的 WPF 应用代码:

public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private void Start_Click(object sender, RoutedEventArgs e)
{
using (host = new ServiceHost(typeof(UfebsSignService)))
{
host.Open();
}
Stop.IsEnabled = true;
Start.IsEnabled = false; 
}
private void Stop_Click(object sender, RoutedEventArgs e)
{
host.Close();
Stop.IsEnabled = false;
Start.IsEnabled = true;
}

App.config code(wpf app):

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata  /> <!--httpGetEnabled="false"-->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehavior" name="UfebsSignServiceLibrary.UfebsSignService">
<host>
<baseAddresses>
<!--<add baseAddress="http://localhost:8080/UfebsSignService" />-->
<add baseAddress="net.tcp://localhost:8585/UfebsSignService/" />
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" contract="UfebsSignServiceLibrary.IUfebsSignService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />   
</service>
</services>
</system.serviceModel>

无法识别 URI 前缀。 元数据包含无法解析的引用:"net.tcp://localhost:8585/UfebsSignService/"。 无法连接到 net.tcp://localhost:8585/UfebsSignService/。连接尝试持续了 00:00:02.0140574 的时间跨度。TCP 错误代码 10061

代码片段中有一个小问题。当我们使用 USING 语句时,它会自动释放托管资源。请考虑使用以下代码启动服务主机。

host = new ServiceHost(service);
host.Open();

如果问题仍然存在,请随时告诉我。

相关内容

最新更新