简体   繁体   English

无法使用netTcpBinding将WCF服务引用添加到客户端项目

[英]Can't add WCF service reference to client project using netTcpBinding

I have a WCF service that uses NetTcpBinding and I'd like to host it in a WPF application. 我有一个使用NetTcpBinding的WCF服务,我想将其托管在WPF应用程序中。 The service seems to start correctly, but when I'm trying to get it's metadata using 'Add service reference' in visual studio I get this exception: 该服务似乎正常启动,但是当我尝试在Visual Studio中使用“添加服务引用”获取其元数据时,出现此异常:

The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8000/Mandrake/mex'.

My service project's App.config file: 我的服务项目的App.config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
  <compilation debug="true" />
</system.web>
<system.serviceModel>
  <services>
    <service name="Mandrake.Service.OTAwareService">
      <endpoint address="OTService" binding="netTcpBinding" contract="Mandrake.Service.IOTAwareService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint name="MEX" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:8000/Mandrake/" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata/>
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

</configuration>

And the code in the hosting application: 以及托管应用程序中的代码:

Uri baseAddress = new Uri("net.tcp://localhost:8000/Mandrake");
ServiceHost host = new ServiceHost(typeof(OTAwareService), baseAddress);

try
{
    host.AddServiceEndpoint(typeof(IOTAwareService), new NetTcpBinding(), "OTService");

}
catch (CommunicationException e)
{
    Console.WriteLine(e.Message);
    host.Abort();
}

The solutions I found to the problem were mainly about adding the 'serviceMetaData' to the service config or providing a mex endpoint. 我发现的问题解决方案主要是将'serviceMetaData'添加到服务配置中或提供mex端点。 Could you suggest something? 你能建议点什么吗?

Edit: 编辑:

Final config: 最终配置:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="NewBehavior0">
      <serviceMetadata />
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="Mandrake.Service.OTAwareService" behaviorConfiguration="NewBehavior0">
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8036/OTService"/>
      </baseAddresses>
    </host>

    <endpoint address="" binding="netTcpBinding" name="TcpEndpoint" contract="Mandrake.Service.IOTAwareService" />
    <endpoint address="mex" binding="mexTcpBinding" name="MetadataEndpoint" contract="IMetadataExchange" />

  </service>
</services>
</system.serviceModel>

Hosting application: 托管应用程序:

host = new ServiceHost(typeof(OTAwareService));
host.Open();

I've managed to figure it out, after enabling the serviceDebug's includeExceptionDetailInFaults it was pretty clear. 在设法启用serviceDebug的includeExceptionDetailInFaults之后,我设法弄清楚了这一点。

Mandrake.Service.IOTCallback.Send operation references a message element [http://tempuri.org/:Send] that has already been exported from the Mandrake.Service.IOTAwareService.Send operation

So there was a Send(OTMessage) operation in the service contract and in the callback interface as well. 因此,在服务协定和回调接口中也都有一个Send(OTMessage)操作。 A rather ugly mistake but I thought I would leave the solution here in case it helps anyone. 这是一个相当丑陋的错误,但我想我会把解决方案留在这里,以防万一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在同一解决方案中为WCF项目的客户端类添加服务引用 - Can't add service reference to client class for WCF project within same solution NetTcpBinding - 自托管WCF - 无法连接客户端 - NetTcpBinding - Self-Hosted WCF - Can't get client connected 由于出现“没有端点监听”错误而无法连接到NetTcpBinding WCF服务 - Can't connect to NetTcpBinding WCF service due to “There was no endpoint listening” error 使用客户端证书将 WCF 服务引用添加到 Visual Studio 2022 项目 - Add WCF Service Reference to Visual Studio 2022 Project with Client Certificate WCF服务库项目找不到对其他项目的引用 - WCF service library project can't find reference to other project 如何为netTcpBinding服务添加服务引用? - How to add service reference for a netTcpBinding service? 无法将Azure VM上托管的WCF服务引用添加到VS2015项目 - Can't add WCF service reference hosted on Azure VM to VS2015 project 获得IEnumerable <T> 使用NetTcpBinding WCF服务的语义? - Getting IEnumerable<T> semantics with a NetTcpBinding WCF service? 无法将服务引用添加到自托管WCF服务 - Can't Add Service Reference to self-hosted WCF Service nettcpbinding如何正确添加服务引用? - nettcpbinding how add service reference correctly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM