WCF Object Types
-
Hi All, I'm a WCF newbie and am struggling with an issue that I'm sure has a solution. My problem is quite simple. I have one service that generates orders. I have a completely separate service that is doing things with orders. The second service has an operation that accepts a parameter of type "order" and has a Service Reference to the order generation service. In my client code it is not able to convert the type produced by the order service as the type expected as a parameter to the processing service. The error I get is: Value of type 'ConsoleApplication1.HCOPSVC.HCOPOrder' cannot be converted to 'ConsoleApplication1.LOCALSERVICE.HCOPOrder'. The conversion appears on the line that references the second service. I've tried to define a namespace for both services, hoping that would allow WCF to consider the two types equal; however, that has not worked. Is there anyway to allow objects to be passed to different services without proxy classes? Any help or guidance is greatly appreciated. Thnx
Sub Main() Dim oOrderSvc As New HCOPSVC.OrderWCFServiceClient() Dim oOrder As HCOPSVC.HCOPOrder Try oOrder = oOrderSvc.GetOrder(8817398, "BZ") Console.WriteLine("Order Retrieved") Dim oPassing As New LOCALSERVICE.OrderPassingProofClient() oPassing.ProcessOrder(**oOrder**) Catch ex As Exception Console.WriteLine("ERROR:" & ex.Message) Finally If oOrderSvc.State = ServiceModel.CommunicationState.Faulted Then oOrderSvc.Abort() Else oOrderSvc.Close() End If End Try Console.WriteLine("Press any key to exit") Console.ReadLine() End Sub
-
Hi All, I'm a WCF newbie and am struggling with an issue that I'm sure has a solution. My problem is quite simple. I have one service that generates orders. I have a completely separate service that is doing things with orders. The second service has an operation that accepts a parameter of type "order" and has a Service Reference to the order generation service. In my client code it is not able to convert the type produced by the order service as the type expected as a parameter to the processing service. The error I get is: Value of type 'ConsoleApplication1.HCOPSVC.HCOPOrder' cannot be converted to 'ConsoleApplication1.LOCALSERVICE.HCOPOrder'. The conversion appears on the line that references the second service. I've tried to define a namespace for both services, hoping that would allow WCF to consider the two types equal; however, that has not worked. Is there anyway to allow objects to be passed to different services without proxy classes? Any help or guidance is greatly appreciated. Thnx
Sub Main() Dim oOrderSvc As New HCOPSVC.OrderWCFServiceClient() Dim oOrder As HCOPSVC.HCOPOrder Try oOrder = oOrderSvc.GetOrder(8817398, "BZ") Console.WriteLine("Order Retrieved") Dim oPassing As New LOCALSERVICE.OrderPassingProofClient() oPassing.ProcessOrder(**oOrder**) Catch ex As Exception Console.WriteLine("ERROR:" & ex.Message) Finally If oOrderSvc.State = ServiceModel.CommunicationState.Faulted Then oOrderSvc.Abort() Else oOrderSvc.Close() End If End Try Console.WriteLine("Press any key to exit") Console.ReadLine() End Sub
This is my understanding of the your question: 1. You have two WCF services. 2. Both the services have operations that accept Order object as a parameter. 3. You are trying to pass Order object from one service to another. Correct me if I am wrong. Here is the solution for the above mentioned problem: You cannot pass the object right away. If both the services are using same data contracts, they should be consuming the same class library (dll) which has all the data contracts. That way you could have used objects interchangeably. Since that is not the case anymore, you will need to translate one object to another by yourself. Have a method that takes in Order object from one service and returns Order object of another service. This method should copy the values for all the properties from one to another. Hope this helps. :)
"The worst code you'll come across is code you wrote last year.", wizardzz[^]
-
Hi All, I'm a WCF newbie and am struggling with an issue that I'm sure has a solution. My problem is quite simple. I have one service that generates orders. I have a completely separate service that is doing things with orders. The second service has an operation that accepts a parameter of type "order" and has a Service Reference to the order generation service. In my client code it is not able to convert the type produced by the order service as the type expected as a parameter to the processing service. The error I get is: Value of type 'ConsoleApplication1.HCOPSVC.HCOPOrder' cannot be converted to 'ConsoleApplication1.LOCALSERVICE.HCOPOrder'. The conversion appears on the line that references the second service. I've tried to define a namespace for both services, hoping that would allow WCF to consider the two types equal; however, that has not worked. Is there anyway to allow objects to be passed to different services without proxy classes? Any help or guidance is greatly appreciated. Thnx
Sub Main() Dim oOrderSvc As New HCOPSVC.OrderWCFServiceClient() Dim oOrder As HCOPSVC.HCOPOrder Try oOrder = oOrderSvc.GetOrder(8817398, "BZ") Console.WriteLine("Order Retrieved") Dim oPassing As New LOCALSERVICE.OrderPassingProofClient() oPassing.ProcessOrder(**oOrder**) Catch ex As Exception Console.WriteLine("ERROR:" & ex.Message) Finally If oOrderSvc.State = ServiceModel.CommunicationState.Faulted Then oOrderSvc.Abort() Else oOrderSvc.Close() End If End Try Console.WriteLine("Press any key to exit") Console.ReadLine() End Sub
In addition to d@nish's reply...
Wauna wrote:
I've tried to define a namespace for both services, hoping that would allow WCF to consider the two types equal;
The namespaces would need to be the same for both, and the error message shows clearly they are not. As d@nish mentioned, if your services are in separate assemblies, then you should put the HCOPOrder in a library assembly and both service assemblies should reference the library. Then everyone shares the same namespace.class. If both your services are in the same assembly, then you shouldn't have two copies (in two namespaces) of the class definition....there should only be one.
Mark Salsbery Microsoft MVP - Visual C++ :java: