2

I am implementing a distributed processing system for medical data. I have multiple clients and servers. Clients have data and they send requests to server for processing.

I have to transfer two values to server and get one list back. The server implementation is defined as:

[ServiceContract]
public interface ServerInterface
{
    [OperationContract]
    List<Triangle> ServerFunction(Grid g, double isolevel);
} 

public class ServerImpl : ServerInterface
 {
       public List<Triangle> ServerFunction(Grid g, double isolevel)
       {/*Implementation*/}
 }

the grid class is defined as:

[Serializable]
 public class Grid
 {
    public Point3D[] p = new Point3D[8];
    public Int32[] val = new Int32[8];
 }

And the Triangle class as

  [Serializable]
  public class Triangle
  {
     public Point3D[] p = new Point3D[3];
  }

I created client and server side implementation and isolevel value passes fine but grid doesnot get passed properly.

The server creates WCF service using this code:

        Uri baseAddress = new Uri("http://localhost:6525/ServerObject");

        using (ServiceHost host = new ServiceHost(typeof(ServerImpl), baseAddress))
        {
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            host.Description.Behaviors.Add(smb);

            host.Open();
            Console.ReadKey();
         }

the portion of code calling the server for results is :

var myBinding = new BasicHttpBinding();
var myEndPoint = new EndpointAddress("http://localhost:6525/ServerObject");
var myChannelFactory=new ChannelFactory<ServerInterface>(myBinding,myEndPoint);
ServerInterface si=null;
si = myChannelFactory.CreateChannel();


List<Triangle> triList=si.ServerFunction(Grid g,double isoValue);

It never returns the list of triangles(always returns null).

This code was tested before converting to Distributed and was working properly.

I am using WCF and I tried converting the Grid and triangles to string values and passing them, it works but is very slow. The algorithm itself takes good amount of time so extra processing time is not desirable. Any ideas?

4
  • Have you tried using DataContract instead of Serializable? Commented Nov 25, 2013 at 14:12
  • I tried but the Grid object reaching the server is null. Commented Nov 25, 2013 at 14:46
  • Sily question, but have you confirmed that your grid-object isn't nullwhen you make your call to the service? Commented Nov 25, 2013 at 16:04
  • yes. Its created created and checked right before passing. When I try to access the gridcell object from server it says object reference not set to instance of an object. Commented Nov 25, 2013 at 17:03

2 Answers 2

1

You should use the DataContractSerializer by adding the [DataContract] attribute to the classes you want to serialize. Then add the [DataMember] attribute to each of the classe's members. So you'd have something like this:

[DataContract]
public class Grid
{
   [DataMember]
   public Point3D[] p = new Point3D[8];

   [DataMember]
   public Int32[] val = new Int32[8];
}

More info can be found on Microsoft's site here.

Sign up to request clarification or add additional context in comments.

2 Comments

I did that but grid object is not being passed. When I try to access the grid object from server side it says object reference not set to an instance of object. I dont understand why.
In addition to adding the attributes mentioned above to your classes, you actually have to serialize and deserialize the objects to pass them around. Here's an excerpt from Microsoft's site on how to Serialize an object using the DataContractSerializer Person p = new Person(); DataContractSerializer dcs = new DataContractSerializer(typeof(Person)); XmlDictionaryWriter xdw = XmlDictionaryWriter.CreateTextWriter(someStream,Encoding.UTF8 ); dcs.WriteObject(xdw, p); Instructions are available at the link I mentioned
1

I took your code and implemented the server code below:

        var v = new List<Triangle>();
        var t1 = new Triangle();
        t1.p = new Point3D[3];
        t1.p[0] = new Point3D(1,2,3);
        t1.p[1] = new Point3D(2,2,3);
        t1.p[2] = new Point3D(3,2,3);

        v.Add(t1);
        return v;

and the client received the triangle coordinates nicely. Have you verified that your server is actually populating the array correctly? below is my simple client code. To create the proxy I just started the server and from the client project I added a service reference to

http://localhost:6525/ServerObject?wsdl 

-

        var c = new ServerInterfaceClient();
        var v=c.ServerFunction(new Grid(), 34.3);
        foreach (var triangle in v)
        {
            Console.WriteLine("X:"+ triangle.p[0]._x);
            Console.WriteLine("y:"+ triangle.p[0]._y);
            Console.WriteLine("z:"+ triangle.p[0]._z);
        }

Sorry I couln't be of more help, but I would add some loggin to both server and client side to try to see where the objects go missing. There shouldn't be anything wrong with your wcf setup.

1 Comment

The problem here seems like the Grid object isnot reaching the server. The triangle positions are calculated using the Grid value. How do i confirm my object is reaching the server?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.