C# 如何添加具有固定端口的WCF服务引用?
我在C# 如何添加具有固定端口的WCF服务引用?,c#,.net,wcf,.net-4.0,service-reference,C#,.net,Wcf,.net 4.0,Service Reference,我在app.config <services> <service behaviorConfiguration="serviceBehavior" name="AgileServer.AgileService"> <endpoint address="AgileService" binding="basicHttpBinding" name="basicHttp" contract="AgileServer.AgileService" />
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>
当我尝试向我的服务添加服务引用时(通过单击“添加服务引用”提示符中的“发现”),URI显示为http://localhost:33908/AgileService.svc
我希望我的服务使用http://localhost:24453/AgileService
作为URI。我如何才能做到这一点?您需要
- 启动并运行Windows服务中的WCF服务
- 不要单击“发现”,而是键入/粘贴要连接到的URL-或者使用基本地址(
)或MEX端点的地址(http://localhost:24453/AgileService
)http://localhost:24453/AgileService/mex
http://localhost:24453/AgileService/AgileService
由您的基本地址组成(http://localhost:24453/AgileService
)加上端点上的相对地址(AgileService
)。您需要
- 启动并运行Windows服务中的WCF服务
- 不要单击“发现”,而是键入/粘贴要连接到的URL-或者使用基本地址(
)或MEX端点的地址(http://localhost:24453/AgileService
)http://localhost:24453/AgileService/mex
http://localhost:24453/AgileService/AgileService
由您的基本地址组成(
http://localhost:24453/AgileService
)加上端点上的相对地址(AgileService
)。回答得很好,谢谢。那么,使用Discover是否合适呢?它创建的服务引用是否总是只能用于本地测试?@Eric:我自己从来没有使用过“发现”—不确定它到底能帮到你什么。。。。。。服务引用创建是一个成熟的、生产就绪的客户机-它绝对不仅仅是为了测试!它创建了客户端配置-但是你当然可以在生产中调整它(使用不同的URL)-但是创建的客户端代码是真实的-不仅仅是用于测试!回答得很好,谢谢。那么,使用Discover是否合适呢?它创建的服务引用是否总是只能用于本地测试?@Eric:我自己从来没有使用过“发现”—不确定它到底能帮到你什么。。。。。。服务引用创建是一个成熟的、生产就绪的客户机-它绝对不仅仅是为了测试!它创建了客户端配置-但是你当然可以在生产中调整它(使用不同的URL)-但是创建的客户端代码是真实的-不仅仅是用于测试!