2010-06-15 105 views
5

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

MyFaultMyDto兩種標記[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建。

回答

8

10.20.30.40:8080不是有效的URL。你想要http://10.20.30.40:8080


這裏是我的診斷思維過程,在情況下,它可以幫助任何人:

  1. 異常通常不會說謊。他們通常意思就是他們所說的。訣竅是瞭解他們如何可能說出真相。
  2. 該異常說:「此操作不支持相對URI」。如果這是真的,那麼這意味着一個操作正在執行,它被賦予了一個相對URL,但它不支持相對URI。
  3. 該OP然後說,當他運行應用程序時「除了我從綁定中刪除proxyAddress =」10.20.30.40:8080「」。

那裏,在我面前,是一個相對的URI。當他刪除它時,「操作」起作用,所以我推斷這是提供給不支持它們的「操作」的相對URI。

你不一定非要成爲福爾摩斯才能解決這個問題。關鍵是能夠立即看到URI前面沒有scheme://,因此它是相對的。

+0

哇!一千頁長的問題,一行答案,你打了指甲。剛剛測試過,作品標記爲答案。我躲在恥辱。無論如何:我問的很好。非常感謝你! (編輯:Lol,「你可以在2分鐘內接受答案」,你太快了,現在等待2分鐘......) – Slauma 2010-06-15 19:21:42

+1

Slauma,你問過這個問題很好! ))因爲我陷入了非常相似的情況。之所以在我的情況下使用不帶「http://」的代理URL是因爲它是從另一個地方(參數爲wget.exe)複製的,因爲它是合法的語法。 – Ivan 2013-08-09 08:21:54