简体   繁体   English

如何添加具有固定端口的WCF服务引用?

[英]How do you add a WCF service reference with a fixed port?

I have a WCF service being hosed by a Windows Service with this in the app.config 我有一个Windows服务正在通过WFP服务在app.config中设置的app.config

  <services>
    <service behaviorConfiguration="serviceBehavior" name="AgileServer.AgileService">
      <endpoint address="AgileService" binding="basicHttpBinding" name="basicHttp" contract="AgileServer.AgileService" />
      <endpoint binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:24453/AgileService" />
        </baseAddresses>
      </host>
    </service>

When I try to add a service reference to my service (by clicking "Discover" in the "Add Service Reference" prompt), the URI shows up as http://localhost:33908/AgileService.svc I want my service to use http://localhost:24453/AgileService as the URI. 当我尝试将服务引用添加到我的服务时(通过单击“添加服务引用”提示中的“发现”),该URI显示为http://localhost:33908/AgileService.svc我希望我的服务使用http://localhost:24453/AgileService作为URI。 How can I accomplish this? 我该怎么做?

You need to 你需要

  • have the WCF service in your Windows service up and running 在Windows服务中启动并运行WCF服务
  • do not click on Discover , but instead type in / paste in the URL you want to connect to - either use the base address ( http://localhost:24453/AgileService ) or the MEX endpoint's address ( http://localhost:24453/AgileService/mex ) 不要单击“ Discover ,而是输入/粘贴要连接的URL-使用基地址( http://localhost:24453/AgileService )或MEX端点的地址( http://localhost:24453/AgileService/mex

Doing this will connect to the URL defined, and the service metadata will be retrieved and used to create a client-side proxy for the service. 这样做将连接到定义的URL,并且将检索服务元数据并将其用于创建该服务的客户端代理。

Just as a side-note: your actual service URL will be: 就像一个旁注:您的实际服务URL将是:

http://localhost:24453/AgileService/AgileService

made up of your base address ( http://localhost:24453/AgileService ) plus the relative address on the endpoint ( AgileService ). 由您的基本地址( http://localhost:24453/AgileService加上端点的相对地址( AgileService )组成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM