例外「不支持相對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