我想我已经尝试了一切,但我无法让一个简单的 net.tcp WCF 服务工作,我需要一些帮助。我在 Visual Studio 2015 中有一个 WCF net.tcp 项目,它具有以下服务类:
namespace AppRefactory.JdmCommSample
{
public enum DocType { Labels, Releases, Artists }
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface ILabelOperations
{
[OperationContract]
bool PassLabelProcess(string targetAddress, string hostCommand, MusicLabelContract musicLabel);
// TODO: Add your service operations here
}
}
下面在 LabelProcess.svc 文件中实现服务:
namespace AppRefactory.JdmCommSample
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "MusicLabel" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select MusicLabel.svc or MusicLabel.svc.cs at the Solution Explorer and start debugging.
public class LabelOperations : ILabelOperations
{
public bool PassLabelProcess(string targetAddress, string hostCommand, MusicLabelContract musicLabel)
{
throw new NotImplementedException();
}
}
}
我已经对服务的 web.config 进行了广泛的阅读,并使用了 ServiceModelReg.exe 来帮助我——但以下是服务项目的 web.config 的当前版本:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="epTcpBehavior">
<endpointDiscovery />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviorConfig">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false"
includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
<add binding="netTcpBinding" scheme="net.tcp" bindingConfiguration="InsecureTcp" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service behaviorConfiguration="ServiceBehaviorConfig" name="AppRefactory.JdmCommSample.LabelOperations">
<endpoint address="LabelService" binding="netTcpBinding" bindingConfiguration="InsecureTcp"
name="LabelOperations" contract="AppRefactory.JdmCommSample.ILabelOperations" />
<endpoint address="netTcpMex" binding="mexTcpBinding" bindingConfiguration="NewBinding0"
name="NetTcpMEX" contract="IMetadataExchange" />
<endpoint address="mexhttp" binding="mexHttpBinding" name="HttpMex"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/JdmCommSample/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="InsecureTcp" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
<mexTcpBinding>
<binding name="NewBinding0" />
</mexTcpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
当我转到客户端项目并尝试添加服务引用(在 Visual Studio 2015 中)时,我收到以下错误:
“发现”按钮在单击时不会显示服务,因此我手动输入服务地址:net://localhost/JdmCommSample/LabelOperations.svc 并单击“开始”按钮得到以下结果:
最后,我单击上面错误消息块(在对话框中)中的“详细信息”链接,并获得以下信息:
添加服务引用错误对话框:
无法识别 URI 前缀。元数据包含无法解析的引用:“net.tcp://localhost/JdmCommSample/LabelOperations.svc”。在 net.tcp://localhost/JdmCommSample/LabelOperations.svc 上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用。
很长一段时间以来,我一直收到同样的错误消息,无法弄清楚为什么客户端的元数据一直坚持使用旧的 http:// 地址作为服务,以及为什么它不接受 net.tcp 地址。
最后,我应该快速添加我正在使用以下作为我的开发环境:
- 视觉工作室 2015
- 视窗 10
- IIS 10
...我花时间尝试通过使用支持 net.tcp 的默认服务(有和没有 http)修改 IIS 设置并在 /bin 和编码文件夹中创建一个虚拟应用程序来解决这个问题,以支持交互式调试。上面最后一个对话中描述的错误消息发生了变化——但只是说我正在使用的 net.tcp:// 地址是“不可用的”。
再次,非常感谢您的帮助!!!