0

I'm dipping my foot into WCF and am trying to make a simple test project that can both consume the service as a service and also directly instantiate it's classes and work with them.

I had an earlier working version where data passed was just primitive types. However, when I attempted to convert to using data contracts, I'm getting conflicts in whether it's referencing the proxy-declared version of the contract or the version from the project itself.

Question: Is it possible to do this and if so, how would I resolve the data contract references?

    private void Test()
    {

        MyService fssDirect = new MyService();    // direct instantiation
        MyServiceClient fssService = new MyServiceClient();    // Service proxy

        ClientCredentialsContract Client = new ClientCredentialsContract();
        ResponseDataContract Result = new ResponseDataContract();

        if (CallAsService)
        {
            Result = fssService.Create(Client, Request);
        }
        else
        {
            Result = fssDirect.Create(Client, Request);
        }
    }

In the above, any reference to the RequestDataContract and ClientCredentialsContract types indicates

Warning: The type 'MyContracts.RequestDataContract' in 'C:...\Test\MyServiceProxy.cs' conflicts with the imported type 'MyContracts.RequestDataContract' in 'C:...\MyService\bin\Debug\Contracts.dll'. Using the type defined in 'C:...\Test\MyServiceProxy.cs'.

(Names changed and paths shortened to protect the innocent)

Thanks,

John

4

1 に答える 1

1

サービスのプロキシを作成するときは、データ コントラクトを含むアセンブリを参照してみてください ([サービス参照の追加] を使用する場合は、詳細オプションに移動し、[参照されたアセンブリで型を再利用する] を選択します。svcutil を使用する場合は、/r引数を使用します) 。 . この方法では、ツールはデータ コントラクトを生成せず、競合は発生しません。

于 2012-05-01T21:10:50.207 に答える