WCF:relativeAddress、baseAddress 和绑定 [英] WCF: relativeAddress,baseAddress and binding

查看:39
本文介绍了WCF:relativeAddress、baseAddress 和绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new in WCF and start my experience with a simple file-less application part of which (web.config) you can see below:

    <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>

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

So I expect that my service could be accessible through next address:

  http://localhost:18148/RelativeAddressX.svc

但是我不能这样做.我误解了什么?

but I can't do this. What have I misunderstood?

推荐答案

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

有两种方法可以在 WCF 中为服务指定终结点地址.您可以为每个关联的端点指定一个绝对地址服务,或者您可以为某个服务的 ServiceHost 提供基地址服务,然后为每个关联的端点指定一个地址这个服务是相对于这个基地址定义的.你可以使用这些过程中的每一个来指定端点地址配置或代码中的服务.如果您没有指定一个相对地址,服务使用基地址.

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.

*所以根据你的例子你有基本地址

* So according to your example you have base adress

 http://localhost:18148/

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

and it will be combined with RelativeAddress.svc, as a name of your svc file. And then it will try to combine this string with /RelativeAddressX.svc as a part of endpoint adress. So you will have something like

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

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

Your endpoint must not specify the path to svc in IIS. It should containg only a logical adress, assosiated with this point. So try to change your endpoint to the following:

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

它应该可以通过路径访问

And it should be accessible by the path

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

这篇关于WCF:relativeAddress、baseAddress 和绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆