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

彼德

我有一个使用NetTcpBinding的WCF服务,我想将其托管在WPF应用程序中。该服务似乎正常启动,但是当我尝试在Visual Studio中使用“添加服务引用”获取其元数据时,出现此异常:

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

我的服务项目的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>

以及托管应用程序中的代码:

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();
}

我发现该问题的解决方案主要是将'serviceMetaData'添加到服务配置中或提供mex端点。你能建议点什么吗?

编辑:

最终配置:

<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>

托管应用程序:

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

在设法启用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

因此,在服务协定和回调接口中也都有一个Send(OTMessage)操作。一个相当丑陋的错误,但是我认为如果解决方案对任何人都有帮助,我会把解决方案留在这里。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将WCF服务添加到WCF测试客户端时出错-无法访问服务元数据

使用角度将产品 ID 从客户端添加到服务器

无法在同一解决方案中为WCF项目的客户端类添加服务引用

GWT-将外部Java类添加到客户端项目

将客户端证书添加到单节点服务结构群集

将标题添加到Rabbitmq C客户端

将数据从客户端添加到Apollo?

将Google API客户端添加到Codeigniter

将cookie添加到客户端请求OkHttp

使用Java将客户端角色添加到Keycloak用户

将Google Translate客户端库添加到Android项目时,为什么会出现此错误?

是否需要将新添加的Couchbase服务器添加到客户端配置中才能使用?

“无法将sta添加到内核驱动程序” hostapd-无法连接10个以上的客户端

Pusher:将Swift(iOS)发布者/服务器添加到Raspberry Python订阅者/客户端

如何从另一个客户端或服务器将文本添加到列表中?

WCF Action attribute.change 导致客户端在更新服务引用时无法看到功能

如何将客户端ID添加到Java的Google Drive客户端API

简单的OData客户端-如何将代理设置添加到OData客户端

无法将服务引用添加到OData端点

使用Java客户端将文件添加到GitHub-org.eclipse.egit.github.core

将Access-Control-Allow-Origin标头添加到使用PHP客户端库上传的文件中

将JavaScript客户端添加到IdeniityServer4并使用用户名和密码登录

运行 winforms 客户端,不使用引用的 wcf 服务启动 iisexpress - 在 Windows 10 下。想法?

将Bytescout的引用添加到我的项目后无法使用

将客户端验证失败添加到ASP.NET MVC ModelState

将客户端证书添加到Spring Boot应用程序

如何将请求标头添加到基于Tyrus注释的客户端

HL7 HAPI-FHIR将cookie添加到客户端请求

如何将 luster 文件系统客户端添加到 BlueData 容器?