[英]WCF Service(NetTcpBinding) + host on managed WPF application
[英]WCF Service Library with NetTcpBinding
我在使用NetTcpBinding時遇到困難。
當我運行WCFservice時,得到以下信息:
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。
我該如何解決這個問題?
編輯:這是我的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中右鍵單擊虛擬目錄/應用程序,然后選擇“管理應用程序”->“高級設置”。 在“啟用的協議”部分中,添加net.tcp,例如:http,net.tcp。 即使您已經在站點級別添加了此協議,這也是必需的。
在這個部分
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/.../" />
</baseAddresses>
</host>
添加一個net.tcp://基址。
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/" />
<add baseAddress="net.tcp://localhost"/>
</baseAddresses>
</host>
您可以共享端口,這並不難。
確保在IIS中選擇啟用的協議時(右鍵單擊站點->管理網站->高級設置),不要使用空間。 如果您使用的是“ http,net.tcp”而不是“ http,net.tcp”,它將無法正常工作,而是給您此確切的錯誤。
此處的更多信息: http : //www.weeksofprogramming.com/post/Could-not-find-a-base-address-Check-for-spaces-in-IIS7.aspx
在IIS站點中配置net.tcp綁定,並將啟用的協議設置為“使用高級設置的http,net.tcp”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.