【发布时间】:2011-03-04 03:47:12
【问题描述】:
“相对 URI 不支持此操作。”异常发生在以下情况:
我有 WCF 服务:
[ServiceContract(ProtectionLevel=ProtectionLevel.None)]
public interface IMyService
{
[OperationContract]
[FaultContract(typeof(MyFault))]
List<MyDto> MyOperation(int param);
// other operations
}
public class MyService : IMyService
{
public List<MyDto> MyOperation(int param)
{
// Do the business stuff and return a list of MyDto
}
// other implementations
}
MyFault 和MyDto 是两个非常简单的类,用[DataContract] 属性标记,每个类只有三个[DataMember] 类型为string, int and int?。
此服务与 ASP.NET 应用程序一起托管在 Win 2008 服务器上的 IIS 7.0 中。我正在使用一个 SVC 文件MyService.svc,它直接位于网站的根目录中。 web.config中的服务配置如下:
<system.serviceModel>
<services>
<service name="MyServiceLib.MyService">
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="wsHttpBindingConfig"
contract="MyServiceLib.IMyService" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBindingConfig">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
这似乎有效,因为我可以在浏览器中输入地址 http://www.domain.com/MyService.svc 并获得“这是 Windows Communication Foundation 服务”-欢迎页面。
使用该服务的客户端之一是控制台应用程序:
MyServiceClient aChannel = new MyServiceClient("WSHttpBinding_IMyService");
List<MyDto> aMyDtoList = aChannel.MyOperation(1);
它具有以下配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="true" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false"
proxyAddress="10.20.30.40:8080" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows"
negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://www.domain.com/MyService.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IMyService"
contract="MyService.IMyService"
name="WSHttpBinding_IMyService" />
</client>
</system.serviceModel>
当我在客户站点的生产服务器上运行此应用程序时,调用 aChannel.MyOperation(1) 会引发以下异常:
相对 URI 不支持此操作。
当我使用完全相同的配置在我的开发 PC 上运行此客户端应用程序时,除了我从绑定中删除了 proxyAddress="10.20.30.40:8080",该操作正常运行。
现在我真的不知道指定代理服务器地址可能与绝对或相对 URI 有什么关系。在生产或开发机器上运行客户端时,我能看到的唯一区别是是否使用代理服务器。
是否有人知道此异常在这种情况下可能意味着什么以及如何解决问题?
提前感谢您的帮助!
编辑:
如果它应该很重要:服务和客户端是使用 .NET Framework 4 中的 WCF 构建的。
【问题讨论】:
标签: wcf wcf-client