例外“不支持相对URI此操作。”发生在下列情况:奇怪的例外通过代理服务器连接到WCF服务时
我有一个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]
属性非常简单的类,并且每个具有仅string, int and int?
类型的三个[DataMember]
。
此服务与ASP.NET应用程序一起位于Win 2008 Server上的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通讯基础服务” - 欢迎页面。
一位客户消费的服务是一个控制台应用程序:
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框架4与WCF建。
哇!一千页长的问题,一行答案,你打了指甲。刚刚测试过,作品标记为答案。我躲在耻辱。无论如何:我问的很好。非常感谢你! (编辑:Lol,“你可以在2分钟内接受答案”,你太快了,现在等待2分钟......) – Slauma 2010-06-15 19:21:42
Slauma,你问过这个问题很好! ))因为我陷入了非常相似的情况。之所以在我的情况下使用不带“http://”的代理URL是因为它是从另一个地方(参数为wget.exe)复制的,因为它是合法的语法。 – Ivan 2013-08-09 08:21:54