0

I created 3 projects: class library (referenced by two following), web service and client application. Web service is added as Service reference (Connected Service) to the client project. The problem is that I need to get from web service an object of type ClassLibrary.AB but by a default I got ClientProject.ServiceProject.AB (as the service reference seems to work as any other reference it expects AB type to be a member of reference type, in this scenario ServiceProject.AB). I tried to switch "Configure Service Reference... > Reuse types in referenced assemblies" on and off but without success. Could you please give me some directions how should I configure it to get object of ClassLibrary namespace? Code for clarification:

Class library AB class:

using System;
using System.Runtime.Serialization;

namespace ClassLibrary
{
    [Serializable]
    [DataContract(Name = "AB", Namespace = "ClassLibrary")]
    public class AB
    {
        [DataMember(Name = "a")]
        private int a;
        [DataMember(Name = "b")]
        private byte[] b;
        <some_more_methods_here>
    }
}

Web service method:

using ClassLibrary;
[...]
[WebMethod]
public AB calledMethod(byte[] x)
{
    int a = [...]
    byte[] b = [...]
    AB ab = new AB(a, b);    
    return ab;
}

Failing client code:

using ClassLibrary;
[...]
byte[] x = [...]
var serviceProjectSoapClient = new ServiceProject.ServiceProjectSoapClient();
AB ab = new AB();
ab = serviceProjectSoapClient.calledMethod(x); // here error occurs because of types missmatch
DerStarkeBaer
  • 669
  • 8
  • 28
TajniakOsz
  • 83
  • 1
  • 1
  • 9
  • Hmm, I totaly understand where you are comming from. But The service may not exposed a up-to-date version of the Model. With that consideration out. You may have a insue in your type and class it self. It's not easy to find or debug. https://stackoverflow.com/questions/8286775/. – xdtTransform Dec 03 '19 at 10:51
  • I think class itself is OK because I can use it without any issue if I use `ServiceProject.AB ab = serviceProjectSoapClient.calledMethod(x);` on client side. I also re-built both server and client application several times. – TajniakOsz Dec 03 '19 at 13:24
  • The class will be auto generated, any issue may cause them to not use exisiting library. Like anything like this answer on the question: https://stackoverflow.com/questions/8286775/wcf-common-types-not-reused/12080264#12080264. Your class may not be broken but thing can still stop the reuse. – xdtTransform Dec 03 '19 at 13:27

0 Answers0