user281921
user281921

Reputation: 661

.NET Core RC2 - Consuming External WCF

I'm looking to call a .NET 4.6 service inside my .NET Core RC2 app.

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.

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.

DOes anybody have a example how I could simply consume an external (Not within my project) WCF.

Many Thanks

Upvotes: 2

Views: 4013

Answers (1)

Luke Karski
Luke Karski

Reputation: 96

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:

  1. it uses these attributes on DataContract classes:

    [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

  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

    public interface IMockChannel : Mock.IMockService, System.ServiceModel.IClientChannel
    {
    }
    
  8. And a ClientBase implementation

    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);
    }
    

Upvotes: 4

Related Questions