“www”对我的端点绑定做了什么?

时间:2013-02-17 13:00:30

标签: .net wcf web-services silverlight silverlight-4.0

所以我最近一直在部署一个Silverlight网站,我刚刚注意到一些非常可怕的bug。

我的Silverlight应用程序有5个绑定到同一网站上的Web应用程序上托管的wcf服务,前面只有一个文件夹。假设我的网站 www.test.com 。以下是silverlight应用程序的ServiceReferences.ClientConfig:

的绑定
<client>
    <endpoint address="http://www.test.com/MyWebService/Service1.svc"
        binding="customBinding" bindingConfiguration="CustomBinding_IService1"
        contract="Service1.IService1" name="CustomBinding_IService1" />
    <endpoint address="http://www.test.com/MyWebService/Service2.svc"
        binding="customBinding" bindingConfiguration="CustomBinding_IService2"
        contract="Service2.IService2" name="CustomBinding_IService2" />
    <endpoint address="http://www.test.com/MyWebService/Service3.svc"
        binding="customBinding" bindingConfiguration="CustomBinding_IService3"
        contract="Service3.IService3" name="CustomBinding_IService3" />
    <endpoint address="http://www.test.com/MyWebService/Service4.svc"
        binding="customBinding" bindingConfiguration="CustomBinding_IService4"
        contract="Service4.IService4" name="CustomBinding_IService4" />
    <endpoint address="http://www.test.com/MyWebService/Service5.svc"
        binding="customBinding" bindingConfiguration="CustomBinding_IService5"
        contract="Service5.IService5" name="CustomBinding_IService5" />
</client>

所以我的问题是,当我加载Silverlight应用程序时,在我的IIS网站的根目录下托管的默认aspx页面上,只有当我在URL中键入 test.com 时才能使用连接地址,而不是在我输入 www.test.com 时。它不会失败,但应该通过服务提取的数据不会显示,我无法连接我的凭据。 (因为我的一项服务用于身份验证)

我尝试通过删除 www 来更改我的应用的ServiceReferences.ClientConfig中的值,但情况不会改变一位。如果没有网址中的www,它仍然可以很好地连接,而不是在www开启时。

1 个答案:

答案 0 :(得分:0)

好吧,多亏this lovely post,我得超越了这个问题。我将在这里解释我必须做的事情,以防链接失效。

我所要做的就是在Silverlight代码中更改每个Service Client的每个实例:

Service.IService proxy = new Service.ServiceClient();

到此:

Uri servUri = new Uri("../MyWebService/Service.svc", UriKind.Relative);
EndpointAddress servAddr = new EndpointAddress(servUri);
Service.IService proxy = new Service.ServiceClient("CustomBinding_IService", servAddr);

正如博客文章中所解释的那样,“..”是必要的,因为Silverlight应用程序(通常)位于 ClientBin 文件夹中。

这对我有用了!

相关问题