gpt4 book ai didi

c# - 带有 NetTcpBinding 的 WCF 服务库

转载 作者:太空狗 更新时间:2023-10-29 19:49:32 26 4
gpt4 key购买 nike

我在使用 NetTcpBinding 时遇到了困难。

当我运行我的 WCF 服务时,我得到这个:

System.InvalidOperationException: Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
at System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri, Binding binding, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName)
at System.ServiceModel.ServiceHostBase.ApplyConfiguration()
at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind)
at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)

当我默认使用 WCFSvcHost 运行应用程序时,我得到了这个。没有额外的代码。只是任何新 wcf 服务的默认代码。我只想更改对 tcp 的绑定(bind)。

我该如何解决这个问题?

编辑:这是我的 WCF 的 App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="tcpBinding" transferMode="Streamed" portSharingEnabled="false">
<reliableSession enabled="true" />
<security mode="None">
<transport clientCredentialType="None" protectionLevel="None" />
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="WcfServiceLibrary1.Service1Behavior"
name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="Service" binding="netTcpBinding" bindingConfiguration="tcpBinding"
name="testTcp" contract="WcfServiceLibrary1.IService1" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary1.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

最佳答案

我确定您现在已经解决了这个问题,但它实际上与所有公告板引导您到达的 baseAddresses 无关。我在 http://social.msdn.microsoft.com/forums/en-US/wcf/thread/c9f8d99d-89ee-4573-8528-a21b047bad11 找到了答案.假设您使用的是 IIS 7.x:右键单击 IIS 中的虚拟目录/应用程序,选择管理应用程序 -> 高级设置。在“已启用的协议(protocol)”部分添加 net.tcp,例如:http,net.tcp。即使您已经在站点级别添加了此协议(protocol),这也是必要的。

关于c# - 带有 NetTcpBinding 的 WCF 服务库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1297756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com