如何在特定端口上运行WCF服务

12

我有一个运行在IIS上的.Net 4.0 WCF服务,我没有指定端口,因此假设它运行在80端口。我需要将我的服务安装到已经使用80端口的服务器上,并且网络管理员要求我将我的服务更改为在443端口上运行。我该如何做?我猜想它可以在app.config中配置,但是我找不到一篇文章来展示给我如何做。

这是我的当前app.config:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />


1
你可以映射 IIS 上的另一个端口。只需右键单击具有 WCF 服务的网站,或者如果 WCF 服务应用程序是 IIS 中的网站,则选择编辑绑定,现在可以将 http 更改为监听不同于 80 的端口。 - Rajesh
4个回答

7

我假设您正在使用net.tcp协议运行您的服务。

1) 编辑您的绑定(右键单击“默认网站”选择“编辑绑定”)

enter image description here

2) 服务器端

<service name="YouServiceNameSpace.YourService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="YourBinding" contract="YourContract" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
</service>

3) 客户端

 <endpoint address="net.tcp://YourHost:443/YourServiceDirecotry/YourService.svc"
    behaviorConfiguration="YourBehavior" binding="netTcpBinding"
    bindingConfiguration="YourTcpBinding" contract="YourContract"
    name="YourContractName" />

1
请注意,上述第1点假定您已经启动了IISManager并导航到与运行您的网页的服务器对应的连接。 - Thomas N

6
我们可以使用WCF项目的.csproj文件来实现(在使用VS的情况下)。只需更改相应文件中此xml标记的值即可:
要在端口号60000上运行服务,
<DevelopmentServerPort>60000</DevelopmentServerPort>

1
通常情况下,您应该拥有一个服务节点,至少有一个服务节点和每个节点都有端点,您可以在其中指定端口。更多信息请参见:http://msdn.microsoft.com/en-us/library/ms733932.aspx 例如:
<services>
  <service name="MyNamespace.myServiceType">
   <endpoint 
      address="net.tcp://0.0.0.0:8000" binding="basicHttpBinding" 
      bindingConfiguration="myBindingConfiguration1"
      contract="MyContract"  />
  </service>
</services>

我正在使用 .Net 4.0,因此它是一个简化的配置。请参见此处 http://msdn.microsoft.com/en-us/library/ee530014.aspx。这会增加问题,因为我没有已配置好可以更改的服务。 - Steve Chadbourne
@SteveChadbourne 你仍然可以指定端点和地址,不是吗? - MPelletier

0

在端点地址中指定端口。有关更多详细信息,请参阅this文章中的“在代码中定义端点地址”部分。


只有在自托管WCF服务时,这才能起作用 - 否则,托管环境(IIS)在很大程度上会决定服务的终结点地址... - marc_s

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接