supporting 2D arrays in WCF service - wcf

I need to pass a 2 D array from VBA (excel) to WCF Service.
WCF service does not support 2D arrays in their Operation Contracts.
Can Anyone suggest some alternative for this
e-g,
[VBA]
ReDim Data(nCol, row) As String
This array is a dynamic array in VBA and values are inserted in this. I want to pass this 2D array in a WCF Service .
Dim WCFSvcObj As Object
Set WCFSvcObj = GetObject(WcfServiceAddress)
WCFSvcObj.SendData(data, nCol, row)
[WCF]
[operationContract]
void Senddata(string[,] data, nCol, row)

try using Jagged Arrays
[operationContract]
void Senddata(string[][] data, nCol, row)
It is supported by WCF

Related

List<byte[]> is getting converted to byte[][] in WCF client proxy [duplicate]

This question already has answers here:
Why would a WCF method's return type be changed from a generic collection to an array?
(4 answers)
Closed 7 years ago.
I am having below WCF contract:
[OperationContract]
List<byte[]> GetDocuments(string key);
While consuming this, In client proxy it becomes
public byte[][] GetDocuments(string key)
Return type List< byte[]> is getting converted to byte[][].
Why is this behaviour and How do I get List< byte[]> back as my return type.
WCF serializes your generic List of bytes as a 2 dimension array of bytes. This keeps the information being communicated uncoupled from the .NET framework (which has the implementation for the class List).
While consuming it you can put it back as a List this way:
List<byte> myBytes= new List<Byte>(receivedBytes);

WCF proxy always showing an array and not a List<T>

I'm using WSSF in Visual studio 2010 sp1 and I'm having an issue with WCF collections. It seems that when I create a service reference and change the advanced setting to use a Generic list instead of an array. I still get arrays when trying to use the collections. I would have to convert the array back and forth to a list whenever i want to add or remove objects.
Does anyone know why? or what i need to change for it to work ok. In the data contract designer, i have two types of collections. One is a "Data Contract Collection", another one is "Primitive Data Type Collection".
Any help is appreciated.
I haven't used WSSF but at a base level WCF ILists are handled as arrays. You would have to manually serialise the DTO as a List. Perhaps that's what's happening underneath the covers?
[DataMember]
public IList<Blah> BlahList
{
get { return blah; }
set { blah= new List<Blah>(value);
}
private List<Blah> blah;

Passing Objects Between WCFs

I have an ASP application, which calls an HTTP WCF service, which calls a TCP WCF service (all on different servers). I'm ultimately trying to pass one class object between the three.
I've discovered that I can't do this directly in the HTTP WCF, even though my class object is defined identically in BOTH WCFs. Like this:
Public Function CallOtherFunction(ByVal ThisClass as MyClass)
Dim RetVal as Boolean
RetVal = CallMyOtherWCFFunction(ThisClass)
End Function
Instead I have to:
Public Function CallOtherFunction(ByVal ThisClass as MyClass)
Dim RetVal as Boolean
Dim MyOutgoingClass as MyOtherWCF.MyClass
MyOutgoingClass.MyString = ThisClass.MyString
RetVal = CallMyOtherWCFFunction(MyOutgoingClass)
End Function
My objects are rather large, to say they have a lot of properties. Any way to not have to declare a new variable in my calling function, so my code can be a little easier (like the first example)?
Thanks,
Jason
You can't pass it directly because those are two diffrent types. You can, however, declare your data contracts in a shared assembly (used by the three projects, or at least by the HTTP and the TCP services), an when adding the service reference to create the proxy in the HTTP service, you specify that you want to "reuse types in referenced assemblies". This way it should use the same type in all projects.

REST-based service - handling empty strings

I have developed a REST-based web service. This service takes four parameters. The last two of these parameters may be empty strings. My question is, what is the recommended approach for dealing with empty strings?
Thanks!
You have two options here - either define the parameters in the UriTemplate of the operation as query variables (and not path variables), or if this is not a GET operation, you can let the operation body receive them.
Case 1:
[WebGet(UriTemplate="/GetData?x={x}&y={y}&z={optional1}&w={optional2}")]
string GetData(int x, int y, string optional1, string optional2);
Case 2:
[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string DoSomething(int x, int y, string optional1, string optional2);

.Net List to a SOAP Array and back to a .Net List

Within a Web Service CarService,
I have a class called Car.
Car has a bunch of properties i.e. Car.Color.
CarService has a method called GetCars().
Within GetCar, I have a loop that appends a List of, you guessed it.. Cars.
Dim carList As New List(Of Car)
Do While rdr.Read()
If rdr.GetValue(1).ToString().Length > 0 Then
Dim c As Car = New Car
c.Color = rdr.GetValue(1).ToString()
carList.Add(c)
End If
Loop
GetCars() returns carList.
I also have another page within a different project that consumes that data.
Or at least, I'd like to and here's my problem..
If I do..
Dim myNewCars As List(Of Namespace.Car)
myNewCars = CarServiceProxy.GetCars()
I get:
Value of type '1-dimensional array of Namespace.Car' cannot be converted to 'System.Collections.Generic.List(Of Namespace.Car)'.
What would be the best way to convert this 1-dimensional array' back into a List of Cars?
Without changing anything? Use the List<T> constructor that accepts IEnumerable<T> - so in C# (my VB isn't great):
List<Car> myNewCars = new List<Car>(CarServiceProxy.GetCars());
If you can change things; perhaps consider things like the WCF usage where you can specify the collection type (of all methods) - the scvutil /collectionType: switch. Changing to a WCF stack is non-trivial, though.
With .NET 3.5 (and .NET 4.0) you could do:
Dim myNewCars As List(Of Namespace.Car)
myNewCars = CarServiceProxy.GetCars().ToList()