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

Ste*_*rne 12 wcf

我在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" />
Run Code Online (Sandbox Code Playgroud)

Sur*_*mra 6

我假设你在net.tcp协议上运行你的服务.

1)编辑绑定(右键单击Default Web Site选择Edit Bindings

在此输入图像描述

2)服务器端

<service name="YouServiceNameSpace.YourService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="YourBinding" contract="YourContract" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
</service>
Run Code Online (Sandbox Code Playgroud)

3)客户端

 <endpoint address="net.tcp://YourHost:443/YourServiceDirecotry/YourService.svc"
    behaviorConfiguration="YourBehavior" binding="netTcpBinding"
    bindingConfiguration="YourTcpBinding" contract="YourContract"
    name="YourContractName" />
Run Code Online (Sandbox Code Playgroud)


小智 5

我们可以使用WCF项目的.csproj文件(如果使用VS)来执行此操作.只需在相应的文件中更改此xml标记的值:

要在端口号60000处运行服务,

<DevelopmentServerPort>60000</DevelopmentServerPort>
Run Code Online (Sandbox Code Playgroud)