2014-04-21 67 views
0

我有一個控制檯應用程序中託管幾個WCF服務。所有這些都在代碼使用NetTcpBinding的配置有binding.TransferMode = TransferMode.Streamed 消息合同用於限定它們的操作(見下文代碼的詳細信息)爲什麼我無法在Visual Studio中創建服務引用?

  • RequestMsgContract1,
  • ResponseMsgContract1,
  • ResponseMsgContract2

對於某些神祕的原因,我不能創建一個使用 ResponseMsgContract1和性反應的服務的服務參考MsgContract2消息同時合同(請參閱下面的IMyService1 defenition)。我得到的消息是

無法識別URI前綴。 元數據包含無法解析的引用:'net.tcp:// localhost:8890/MyService1/mex'。 元數據包含無法解析的引用:'net.tcp:// localhost:8890/MyService1/mex'。 如果服務在當前解決方案中定義,請嘗試構建解決方案並再次添加服務引用。沒有任何問題都創造了使用其他兩個服務只RequestMsgContract1和ResponseMsgContract2(見IMyService2)或僅RequestMsgContract1,ResponseMsgContract1(見IMyService3)

服務引用。

我的問題是我的郵件合同有什麼問題,或者我應該在哪些方面尋找一些線索?

我沒有粘貼我的服務配置代碼(因爲我說我不使用xml配置文件),因爲它適用於三種服務中的兩種。我不認爲錯誤的原因是有,但你可以在這裏找到服務主機控制檯應用程序的完整代碼http://pastebin.com/1THhc9mU

// Can't create service reference for this service  
[ServiceContract] 
interface IMyService1 
{ 
    [OperationContract] 
    ResponseMsgContract1 Operation1(RequestMsgContract1 arguments); 

    [OperationContract] 
    ResponceMsgContract2 Operation2(); 
} 

// No problems with service reference creation for this one 
[ServiceContract] 
interface IMyService2 
{ 
    [OperationContract] 
    ResponceMsgContract2 Operation1(); 

    [OperationContract] 
    ResponceMsgContract2 Operation2(RequestMsgContract1 arguments); 
} 

// No problems with service reference creation for this one 
[ServiceContract] 
interface IMyService3 
{ 
    [OperationContract] 
    ResponseMsgContract1 Operation1(); 

    [OperationContract] 
    ResponseMsgContract1 Operation2(RequestMsgContract1 arguments); 
} 

他們使用這三個消息協定

[Serializable] 
[MessageContract] 
public class RequestMsgContract1 
{ 
    [MessageHeader(MustUnderstand = true)] 
    public Guid arg1; 
} 

[Serializable] 
[MessageContract] 
public class ResponseMsgContract1 : IDisposable 
{ 
    [MessageHeader(MustUnderstand = true)] 
    public long Length; 

    [MessageBodyMember(Order = 1)] 
    public System.IO.Stream stream; 

    public void Dispose() 
    { 
     if (stream != null) 
     { 
      stream.Close(); 
      stream = null; 
     } 
    } 
} 

[Serializable] 
[MessageContract] 
public class ResponceMsgContract2 : IDisposable 
{ 
    [MessageHeader(MustUnderstand = true)] 
    public int Length { get; set; } 

    [MessageHeader(MustUnderstand = true)] 
    public string Str1 { get; set; } 

    [MessageBodyMember(Order = 1)] 
    public System.IO.Stream stream { get; set; } 


    public void Dispose() 
    { 
     if (stream != null) 
     { 
      stream.Close(); 
      stream = null; 
     } 
    } 
} 

編輯: 在情況下,它是這裏重現的問題是我的Visual Studio,.Net Framework和操作系統版本

  • Visual Studio 2012(11.0.61030.00 Update 4)
  • .Net框架版本4.5.50709
  • 的Windows 8 Pro的
+0

我剛剛發現如果我將'ResponceMsgContract2.Length'重命名爲'ResponceMsgContract2.Length2',創建服務引用的問題就消失了。但我還是不明白原因。 – technocrat

+0

我在MSDN論壇上提出了同樣的問題。 [鏈接](http://social.msdn.microsoft.com/Forums/en-US/2625032f-757b-44de-b8f0-35d9023b57ab/why-cant-i-create-a-service-reference-in-visual -Studio?論壇= WCF) – technocrat

回答

0

我不明白爲什麼我的問題描述的錯誤發生,但 沒有人提供了一個合適的回答卻又那麼我會告訴我提出的解決方法。也許它會幫助別人。

我發現了兩種方法讓Visual Studio創建服務引用,同時保留所需的所有操作。

  1. 錯誤消失,如果我重新命名ResponceMsgContract2.LengthResponceMsgContract2.Length2使ResponceMsgContract2ResponseMsgContract1沒有具有相同名稱的郵件頭。 爲什麼這有助於我仍然是一個謎。也許這是WCF的錯誤。

  2. 錯誤消失,如果我分裂IMyService1兩個接口:

    [ServiceContract] 
    interface IMyService1_1 
    { 
        [OperationContract] 
        ResponseMsgContract1 Operation1(RequestMsgContract1 arguments); 
    } 
    
    [ServiceContract] 
    interface IMyService1_2 
    { 
        [OperationContract] 
        ResponceMsgContract2 Operation2(); 
    } 
    

兩種變體都沒有好的解決辦法,並有可能是當你不能申請其中的任何情況。但至少是這樣。

相關問題