gpt4 book ai didi

c# - WCF 客户端不考虑主机地址

转载 作者:行者123 更新时间:2023-11-30 22:33:15 25 4
gpt4 key购买 nike

我有以下 WCF 服务配置文件。配置中定义了一个主机。尽管如此,当我从客户端打印服务地址时,它并不知道主机。打印结果为:

http://localhost:3187/Service1.svc/MyFolder

为什么不考虑主机名?我们需要对其进行哪些修改?

注意:我从 VS 2010 运行以运行服务和客户端网站。

        Service1Client myClientService = new Service1Client();
Response.Write(myClientService.Endpoint.Address);

客户端配置(由 Visual Studio 自动生成)

    <client>
<endpoint address="http://localhost:3187/Service1.svc/MyFolder"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="MyWCFReference.IService1" name="WSHttpBinding_IService1">
<identity>
<userPrincipalName value="U16990@ustr.com" />
</identity>
</endpoint>
</client>

服务器端配置为:

<services>

<!--MyService-->
<service name="MyWCFServiceApplication.MyService"
behaviorConfiguration="WeatherServiceBehavior">

<host>
<baseAddresses>
<add baseAddress="http://localhost:80/ServiceModelSamples/FreeServiceWorld"/>
</baseAddresses>
</host>

<endpoint address="MyFolder"
binding="wsHttpBinding"
contract="MyWCFServiceApplication.IService1" />

<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>

</services>


<behaviors>

<serviceBehaviors>

<behavior name="WeatherServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>

</serviceBehaviors>

</behaviors>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

最佳答案

当 WCF 服务通过 IIS 或 ASP.NET 开发服务器(也称为 Cassini)托管在 ASP.NET 进程中时,baseAddresses setting服务配置文件中的 被忽略,因为该服务始终可以通过 SVC 文件的 URL 访问

因此,您在客户端上看到的 URL 是正确的:

http://localhost:3187/Service1.svc/MyFolder

如您所见,服务的基地址成为 Web 服务器上的 SVC 文件的 URL

关于c# - WCF 客户端不考虑主机地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8401196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com