none
Can I have more than one Service Contract in a HPC SOA service? RRS feed

  • Question

  • I have followed the tutorials on the HPC blog and created a simple HPC SOA service. The contract looks like this:

        [ServiceContract]
        public interface ICalculator
        {
            [OperationContract]
            double Add(double a, double b);
        }

    Now I am trying to add a second contract that looks like this:

        [ServiceContract]
        public interface ITest
        {
            [OperationContract]
            double Multiply(double a, double b);
        }

    I have implemented the new interface in the same service class and I added a new endpoint into my service app.config. When I update the service reference on the client in Visual Studio it can see the new endpoint and it generates the correct message contracts, however the new contract will always fail with a System.ServiceModel.ActionNotSupportedException when I try and get the result. The SOA trace just says "Faulted".

    Am I going about this in the right way? I have a large amount of functionality I would like to implement in HPC and just having the one message contract would be messy.

    Wednesday, August 10, 2016 1:00 AM

Answers

  • Hi retep292,

    Yes, you may have multiple operation contracts in one or multiple service contracts. Just note if you have multiple service contracts, you need to explicitly specify it in the service registration file with e.g. contract="EchoSvcLib.IEchoSvc". For details about SOA service registration file, please check this article.

    Regards,

    Yutong Sun

    • Marked as answer by retep292 Wednesday, August 10, 2016 4:56 AM
    Wednesday, August 10, 2016 1:48 AM

All replies

  • Hi retep292,

    Yes, you may have multiple operation contracts in one or multiple service contracts. Just note if you have multiple service contracts, you need to explicitly specify it in the service registration file with e.g. contract="EchoSvcLib.IEchoSvc". For details about SOA service registration file, please check this article.

    Regards,

    Yutong Sun

    • Marked as answer by retep292 Wednesday, August 10, 2016 4:56 AM
    Wednesday, August 10, 2016 1:48 AM
  • Thanks Yutong,

    Do you know of any example solutions that contain more than one service contract?

    Wednesday, August 10, 2016 4:28 AM
  • Hi retep292,

    You may check the HellowWorldR2 sample codes in HPC2012.SampleCode.zip downloadable from here. The EchoService can be easily modified with multiple service contracts with steps below,

    1. Add a new interface e.g. IService2 and implement it together with IService1 in Service1 class.

    2. Add a new endpoint for contract EchoService.IService2 under service EchoService.Service1 in the Web.config file.

    3. Update/Add the service reference for the HelloWorldR2 client projects.

    Please also note that, per a SOA service and session in HPC Pack, only one service contract is supported. The name of the contract is specified in the service registration file. If you want to consume multiple contracts, you need to create mulitple SOA services (via different service registration files that pointing to the same service assembly and different contract names) and multiple SOA sessions.

    Regards,

    Yutong Sun

    Thursday, August 11, 2016 4:02 AM