简体   繁体   English

.NET Core RC2-消耗外部WCF

[英].NET Core RC2 - Consuming External WCF

I'm looking to call a .NET 4.6 service inside my .NET Core RC2 app. 我希望在.NET Core RC2应用程序中调用.NET 4.6服务。

I have tested the service within the WCF Test Client supplied by Microsoft and it works fine, I would like to now consume it inside my .NET Core application but am unsure on how to do that. 我已经在Microsoft提供的WCF测试客户端中测试了该服务,并且运行良好,我现在想在.NET Core应用程序中使用该服务,但不确定如何执行。

I have tried using the svcutil to generate the service reference file but I'm guessing this isn't really designed for the new .NET framework as it uses IExtensibleDataObject which doesn't exist in Core and the namespace System.Runtime.Serialization which now seems to have split into Xml, Primitives and Json. 我曾尝试使用svcutil生成服务参考文件,但我猜这并不是真正为新.NET框架设计的,因为它使用了IExtensibleDataObject(它在Core和命名空间System.Runtime.Serialization中不存在)似乎已经分为Xml,Primitives和Json。

DOes anybody have a example how I could simply consume an external (Not within my project) WCF. 有没有人举过一个例子,说明我如何可以简单地使用外部(不在我的项目中)WCF。

Many Thanks 非常感谢

Microsoft released "WCF Connected Service for .NET Core RC2 and ASP.NET Core RC2" . Microsoft发布了“用于.NET Core RC2和ASP.NET Core RC2的WCF连接服务” It should do the job. 它应该做的工作。

I used it to generate client code for my service and: 我用它为我的服务生成客户端代码,并且:

  1. it uses these attributes on DataContract classes: 它在DataContract类上使用以下属性:

     [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 
  2. It uses [System.Runtime.Serialization.DataMemberAttribute()] for DataContract properties 它对DataContract属性使用[System.Runtime.Serialization.DataMemberAttribute()]

  3. It uses these attributes to define service contract: 它使用以下属性来定义服务合同:

     [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.2.0.0")] [System.ServiceModel.ServiceContractAttribute(ConfigurationName="Mock.IMockService")] public interface IMockService 
  4. This is a sample opertaion definition inside the contract interface: 这是合同接口内的示例操作定义:

     [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); 
  5. To mark request and response objects it uses: 要标记请求和响应对象,它使用:

     [System.ServiceModel.MessageContractAttribute(WrapperName="LookupPerson", WrapperNamespace="http://tempuri.org/", IsWrapped=true)] public partial class LookupPersonRequest 
  6. And property of the request/response is annotated with: 请求/响应的属性带有以下注释:

     [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)] public CepikMock.PersonSearchCriteria criteria; 
  7. Finally it generates basic IClientChannel interface 最后,它生成基本的IClientChannel接口

     public interface IMockChannel : Mock.IMockService, System.ServiceModel.IClientChannel { } 
  8. And a ClientBase implementation 还有一个ClientBase实现

     public partial class MockServiceClient : System.ServiceModel.ClientBase<Mock.IMockService>, Mock.IMockService 
  9. Inside the client class, each service method is exposed like this: 在客户端类内部,每个服务方法都是这样公开的:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM