C# 带有';同一端口';引起错误
我已经读了很多文章来解决这个问题,但我无法解决它 场景 我有一个网站,其中有一个WCF服务和2个主机头C# 带有';同一端口';引起错误,c#,asp.net,wcf,C#,Asp.net,Wcf,我已经读了很多文章来解决这个问题,但我无法解决它 场景 我有一个网站,其中有一个WCF服务和2个主机头 自旋本地主机 spin-localhost.worldwide.co.uk(更改为spin-localhost2) 但使用相同的端口44001我可以访问spin-localhost服务,但无法访问spin-localhost.worldwide.co.uk(现在是spin-localhost2) 编码 <system.serviceModel> <behaviors
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="WindowsAuth" maxReceivedMessageSize="2097152">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior" name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceive">
<endpoint address="http://spin-localhost:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />
<endpoint address="http://spin-localhost.worldwide.co.uk:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />
</service>
</services>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://spin-localhost:44001" />
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
</system.serviceModel>
编辑:我使用的是/Net 3.5而不是/Net 4
参考资料
还有更多
更新1:经过进一步测试,worldwide.bbc.co.uk似乎有错误,因此我将名称和绑定更改为spin-localhost2
<endpoint address="http://spin-localhost2:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />
我可以使用spin-localhost访问第一个服务,但spin-localhost2提供401、401和400(未找到)。和小提琴手核对过了
解决方案(尚未测试):
WCF with IIS将支持具有不同相对地址的多个端点,但我认为IIS不会在同一端口和同一网站/应用程序中支持不同的主机头。尝试创建单独的IIS网站,每个主机头一个,并为每个服务使用单独的serviceModel配置。通过这种方式,您可以为创建的服务使用相同的端口。vesion 4下的.NET WCF不支持多主机头IIS托管,有一些解决方法,这取决于您的.NET版本,或多或少比较复杂
NET 4.0中的WCF支持将此作为一种选择加入功能,通过在配置中使用
启用
这里详细解释了所有内容:IIS在同一端口上支持不同的主机头。NET 4.0对此有解决方案,但不幸的是,我使用的是.NET 3.5。虽然IIS能够为网站中的每个唯一IP地址分配主机hame,但WCF不支持此配置。看看每个IIS IP地址分配都相当于一个单独的基址,但post声明:“一个服务也可以有多个基址,但每个传输只允许每个服务有一个基址。”顺便问一下,您真的需要在服务器上配置主机头以使用相同的名称访问它吗?唯一的区别是,无域地址只能从同一域内的计算机上获得,而域外的所有人都应该使用完整地址。如果可以,请尝试在IIS配置中不使用指定的主机头。正如我在对问题的评论中所说:您真的需要为此配置特定的主机头吗?如果要使用.NET 4和您声明的属性,我是否需要端点属性?很好,我已将项目升级到.NET 4.0,因此问题已得到修复:)谢谢
<endpoint address="http://spin-localhost2:44001/Services/CilsDataReceive.svc" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive" />
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior">
<!-- <serviceMetadata httpGetEnabled="true" />-->
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Windows"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="WindowsAuth" maxReceivedMessageSize="2097152">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceiveBehavior" name="Bbc.Ww.SalesProjections.UI.Services.CilsDataReceive">
<endpoint address="" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Bbc.Ww.SalesProjections.UI.Services.ICilsDataReceive"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>