gpt4 book ai didi

WCF:relativeAddress、baseAddress 和绑定(bind)

转载 作者:行者123 更新时间:2023-12-04 13:47:15 25 4
gpt4 key购买 nike

我是 WCF 的新手,我从一个简单的无文件应用程序部分(web.config)开始我的体验,您可以在下面看到:

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add
factory="System.ServiceModel.Activation.ServiceHostFactory"
relativeAddress="./RelativeAddress.svc"
service="WCF_Transactions.MyService1"/>
</serviceActivations>
</serviceHostingEnvironment>

现在我可以访问服务了

http://localhost:18148/RelativeAddress.svc

然后我添加下一行:

    <services>
<service name="WCF_Transactions.MyService1" behaviorConfiguration="MyBehavior1">
<host>
<baseAddresses>
<add baseAddress="http://localhost:18148/" />
</baseAddresses>
</host>
<endpoint address="/RelativeAddressX.svc" binding="basicHttpBinding" contract="WCF_Transactions.IService1"></endpoint>
</service>
</services>

<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior1">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>

所以我希望我的服务可以通过下一个地址访问:

  http://localhost:18148/RelativeAddressX.svc

但我不能这样做。我误会了什么?

最佳答案

MSDN http://msdn.microsoft.com/en-us/library/ms733749.aspx :*

There are two ways to specify endpoint addresses for a service in WCF. You can specify an absolute address for each endpoint associated with the service or you can provide a base address for the ServiceHost of a service and then specify an address for each endpoint associated with this service that is defined relative to this base address. You can use each of these procedures to specify the endpoint addresses for a service in either configuration or code. If you do not specify a relative address, the service uses the base address.

*因此,根据您的示例,您有基本地址

 http://localhost:18148/

它将与RelativeAddress.svc 结合,作为您的svc 文件的名称。然后它会尝试将此字符串与/RelativeAddressX.svc 组合为端点地址的一部分。所以你会有类似

 http://localhost:18148/RelativeAddress.svc/RelativeAddressX.svc. 

您的端点不得在 IIS 中指定 svc 的路径。它应该只包含一个与这一点相关的逻辑地址。因此,尝试将您的端点更改为以下内容:

 <endpoint  address="RelativeAddressX" binding="basicHttpBinding" contract="WCF_Transactions.IService1"></endpoint>

并且应该可以通过路径访问

 http://localhost:18148/RelativeAddress.svc/RelativeAddressX

关于WCF:relativeAddress、baseAddress 和绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14849183/

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