views:

19

answers:

1

Hi,

I have a client (created using ASMX "Add Web Reference"). The service is WCF. The signature of the methods varies for the client and the Service. I get some unwanted parameteres to the method.

Note: I have used IsRequired = true for DataMember.

Service:    [OperationContract]
            int GetInt();

Client:     proxy.GetInt(out requiredResult, out resultBool);

Could you please help me to make the schame non-varying in both WCF clinet and non-WCF client? Do we have any best practices for that?

using System.ServiceModel;
using System.Runtime.Serialization;

namespace SimpleLibraryService
{
        [ServiceContract(Namespace = "http://Lijo.Samples")]
        public interface IElementaryService
        {
            [OperationContract]
            int GetInt();

            [OperationContract]
            int SecondTestInt();
        }

        public class NameDecorator : IElementaryService
        {
            [DataMember(IsRequired=true)]
            int resultIntVal = 1;

            int firstVal = 1;

            public int GetInt()
            {
                return firstVal;
            }

            public int SecondTestInt()
            {
                return resultIntVal;
            }
        }

}

Binding = "basicHttpBinding"

using NonWCFClient.WebServiceTEST;

namespace NonWCFClient
{
    class Program
    {
        static void Main(string[] args)
        {
            NonWCFClient.WebServiceTEST.NameDecorator proxy = new NameDecorator();

            int requiredResult =0;
            bool resultBool = false;
            proxy.GetInt(out requiredResult, out resultBool);
            Console.WriteLine("GetInt___"+requiredResult.ToString() +"__" + resultBool.ToString());

            int secondResult =0;
            bool secondBool = false;
            proxy.SecondTestInt(out secondResult, out secondBool);
            Console.WriteLine("SecondTestInt___" + secondResult.ToString() + "__" + secondBool.ToString());

            Console.ReadLine();
        }
    }
}

Please help..

Thanks

Lijo

A: 

I don't think you can do much to make this "non-varying" - that's just the way the ASMX client side stuff gets generated from the WCF service. Each client-side stack is a bit different from the other, and might interpret the service contract in the WSDL in a slightly different manner. Not much you can do about that.....

If you don't want this - create a WCF client instead.

A remark on the side:

public class NameDecorator : IElementaryService
{
   [DataMember(IsRequired=true)]
   int resultIntVal = 1;

This is very strange how you're trying to put a DataMember (a field that should be serialized across for the service) into the class that implements the service.....

You should keep your service contract (interface IElementaryService), service implementation (class NameDecorator) and your data contracts (other classes) separate - do not mix data contract and service implementation - this is sure to backfire somehow....

marc_s