.NET Core RC2-消耗外部WCF [英] .NET Core RC2 - Consuming External WCF
问题描述
我希望在.NET Core RC2应用程序中调用.NET 4.6服务.
I'm looking to call a .NET 4.6 service inside my .NET Core RC2 app.
我已经在Microsoft提供的WCF测试客户端中测试了该服务,并且运行良好,我现在想在.NET Core应用程序中使用该服务,但是不确定如何做到这一点.
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.
我尝试使用svcutil生成服务参考文件,但我猜这并不是为新.NET框架真正设计的,因为它使用了IExtensibleDataObject,而Core和命名空间System.Runtime中不存在该IExtensibleDataObject.序列化现在似乎已经分为Xml,Primitives和Json.
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.
有人能举例说明我如何简单地使用外部(不在我的项目中)WCF.
DOes anybody have a example how I could simply consume an external (Not within my project) WCF.
非常感谢
推荐答案
Microsoft发布了.它应该做的.
Microsoft released "WCF Connected Service for .NET Core RC2 and ASP.NET Core RC2". It should do the job.
我用它来为我的服务生成客户端代码,并且:
I used it to generate client code for my service and:
-
它在
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
它对 DataContract
属性使用 [System.Runtime.Serialization.DataMemberAttribute()]
它使用以下属性来定义服务合同:
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
这是合同界面中的示例操作定义:
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);
要标记其使用的请求和响应对象:
To mark request and response objects it uses:
[System.ServiceModel.MessageContractAttribute(WrapperName="LookupPerson", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class LookupPersonRequest
请求/响应的属性用以下注释:
And property of the request/response is annotated with:
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
public CepikMock.PersonSearchCriteria criteria;
最后它会生成基本的 IClientChannel
接口
public interface IMockChannel : Mock.IMockService, System.ServiceModel.IClientChannel
{
}
和 ClientBase
实现
public partial class MockServiceClient : System.ServiceModel.ClientBase<Mock.IMockService>, Mock.IMockService
在客户端类中,每个服务方法都按以下方式公开:
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);
}
这篇关于.NET Core RC2-消耗外部WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!