2016-05-23 38 views
2

我正在調用.NET Core RC2應用程序中的.NET 4.6服務。.NET Core RC2 - 使用外部WCF

我已經在微軟提供的WCF測試客戶端中測試過服務,它工作正常,我想現在在我的.NET核心應用程序中使用它,但我不確定如何做到這一點。

我已經嘗試使用svcutil生成服務引用文件,但我猜這不是真的爲新的.NET框架設計,因爲它使用IExtensibleDataObject,它不存在於Core和名稱空間System.Runtime現在似乎已經分成Xml,Primitives和Json的串行化。

有沒有人有一個例子,我可以簡單地使用外部(不在我的項目中)WCF。

非常感謝

+0

你可以分享服務配置嗎? – Enes

+0

我還沒有找到任何示例,但wcf客戶端庫應在nuget中可用。也許你可以使用實現https://github.com/dotnet/wcf中的一些測試用例。 – Thomas

回答

4

微軟發佈"WCF Connected Service for .NET Core RC2 and ASP.NET Core RC2"。它應該完成這項工作。

我用它來生成客戶端代碼爲我服務:

[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.2.0.0")] 
[System.Runtime.Serialization.DataContractAttribute(Name="Person", Namespace="http://schemas.datacontract.org/2004/07/Mock")] 
public partial class Person : object 
  • 它採用[System.Runtime.Serialization.DataMemberAttribute()]DataContract性質

    1. DataContract類使用這些屬性它使用這些屬性來定義服務合同:

      [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.2.0.0")] 
      [System.ServiceModel.ServiceContractAttribute(ConfigurationName="Mock.IMockService")] 
      public interface IMockService 
      
    2. 這是合同接口內部的樣品opertaion定義:

      [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IMockService/LookupPerson", ReplyAction="http://tempuri.org/IkMockService/LookupPersonResponse")] 
      System.Threading.Tasks.Task<Mock.LookupPersonResponse> LookupPersonAsync(Mock.LookupPersonRequest request); 
      
    3. 要標記請求和響應對象,它使用:請求/響應的

      [System.ServiceModel.MessageContractAttribute(WrapperName="LookupPerson", WrapperNamespace="http://tempuri.org/", IsWrapped=true)] 
      public partial class LookupPersonRequest 
      
    4. 和財產註明:

      [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)] 
      public CepikMock.PersonSearchCriteria criteria; 
      
    5. 最後,它產生基本IClientChannel接口

    6. 而一個ClientBase實現

      public partial class MockServiceClient : System.ServiceModel.ClientBase<Mock.IMockService>, Mock.IMockService 
      
    7. 客戶端類裏面,每個服務方法公開這樣的:

      public System.Threading.Tasks.Task<Mock.LookupPersonResponse> LookupPersonAsync(Mock.LookupPersonRequest request) 
      { 
          return base.Channel.LookupPersonAsync(request); 
      } 
      
  • 相關問題