West Wind Internet and Client Tools
Properties dynamically added
Gravatar is a globally recognized avatar based on your email address. Properties dynamically added
  Marcin
  All
  Nov 26, 2019 @ 05:29pm

Hi Rick,

Need your help, please. I am sending requests to the Post web service. To start with let me show the simple example which works fine. This is array of shipments. Each element is the object with particular shipment parameters.

loShipmentArray = go.DotNet.CreateArray("XXX.ShipmentType")
loShipment=go.DotNet.CreateInstance("XXX.ShipmentType")

go.DotNet.SetProperty(loShipment,"guid",lcGuid)
go.DotNet.SetProperty(loShipment,"address",lcAddress)
go.DotNet.SetProperty(loShipment,"type","TypeA")

loShipmentArray.addItem(loShipment)

then the service call with the array of shipments as the parameter

The above works fine but they also allow to send them the request for shipment type "B". It requires all parameters as type A plus one additional. The matter is that the property related to that additional parameter (PostID) is not mentioned in the "ShipmentType" declaration coming from WSDL file. It need to be added dynamically. So I did the following:

loShipmentArray = go.DotNet.CreateArray("XXX.ShipmentType")
loShipment=go.DotNet.CreateInstance("XXX.ShipmentType")

go.DotNet.SetProperty(loShipment,"guid",lcGuid)
go.DotNet.SetProperty(loShipment,"address",lcAddress)
go.DotNet.SetProperty(loShipment,"type","TypeB")

loPostID = go.DotNet.CreateInstance("XXX.PostIdType")
go.DotNet.SetProperty(loPostID,"id",12345)

addproperty(loShipment,"PostId")
loShipment.PostId=loPostId	

loShipmentArray.addItem(loShipment)

service call.  

There is no error message. I can see with the Fiddler that all parameters related to the properties are sent to the service except the one dynamically added, so the service reply is "missing parameter". Could you comment if it is possible to program such a request in FoxPro+DotNetBridge and if yes what I am doing wrong. With the debugger I can see the value of the dynamically added property to the simple object. It is correct. It is no more visible after it becomes the element of the array.

Disregard any letter mistakes if any. I rewrite the example to make it short and avoid Polish long names.

Regards, Marcin

Gravatar is a globally recognized avatar based on your email address. re: Properties dynamically added
  Rick Strahl
  Marcin
  Nov 27, 2019 @ 12:58am

Not sure I follow what you're trying to do but I'm pretty sure the ADDPROPERTY() call doesn't work because you can't add a property to a COM object. That should blow up your code with a runtime error. If not you got some error handler eating the error.

You can check for wwDotnetBridge errors by checking loBridge.cErrorMsg after any explicit operation that fails (check the result value for SetProperty or whatever).

I'm not seeing what you're doing with the shipment array - you create it but then it's never used.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Properties dynamically added
  Marcin
  Rick Strahl
  Nov 27, 2019 @ 02:18pm

I am also confused because the following code displays the value of the newly added property with no error message:

loPostID = go.DotNet.CreateInstance("XXX.PostIdType")
go.DotNet.SetProperty(loPostID,"id",12345)
addproperty(loShipment,"PostId")
loShipment.PostId = loPostId	
?loShipment.PostId.id    &&  displays  12345

The following code supports the idea that the COM object is not modified because SetProperty generates error message: "name of the property PostId not found"

loPostID= go.DotNet.CreateInstance("XXX.PostIdType")
go.DotNet.SetProperty(loPostID,"id",12345)
addproperty(loShipment,"PostId")
go.DotNet.SetProperty(loShipment,"PostId",loPostID)

I don't know why addproperty does not generate the error but that is what I experienced.

The array created above is passed to the service like that:

addShipmentReply=go.en.addShipment(loShipmentArray)

where 'en' is the address of the object containing all methods,types and properties defined in WSDL provided by the WebService. I have no impact on what is inside and can't modify anything.

My major problem is how to add effectively new property to COM object. I saw the programs using this WebService written in other languages like PHP or C. They all are adding the new property dynamically before passing the object to the service. Can you advice if there is the way to do the same in FoxPro+DotNetBridge.

Marcin

Gravatar is a globally recognized avatar based on your email address. re: Properties dynamically added
  Rick Strahl
  Marcin
  Nov 28, 2019 @ 01:59am

Let me repeat: you can't add a property to a .NET object. It's a static object instance that's set at compile time. It just doesn't work. Either the property is already there, or it isn't.

If ADDPROPERTY() works, it's a fluke of the FoxPro type system and the type is visible to FoxPro, but not to .NET. I can't imagine that that this would work though unless there's an error handler on your end eating the exception that should get thrown.

If you're dealing with WSDL, there should be no dynamic data - the contract is fixed and there has to be a property there. Look in Reflector (or other tool) to review the actual .NET Object structure and that will determine what is available for access.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Properties dynamically added
  Marcin
  Rick Strahl
  Nov 28, 2019 @ 10:53am

Thanks for your comment. If a contract is definitely fixed as you said I look into raw WSDL and I found missing property declared as a choice. Then I found in generated dll the property: items:system.object[] defined in the related type. Now I can set the my problematic property PostId as the system object array element and everything is working fine. Sorry for disturbing with my questions but I did not realize that the property name can be implemented in dll under different name. Even when I was using search and analyze with reflector in dll file it did not display required property.

Reagards, Marcin

Gravatar is a globally recognized avatar based on your email address. re: Properties dynamically added
  Rick Strahl
  Marcin
  Nov 28, 2019 @ 02:12pm

In the WSDL 'optional' means one of two things:

  • Value doesn't have to be provided (ie. value can be null or missing)
  • Value is a collection of values of any type (rare)

The former usually means either there are additional propertiesa to specify whether the value is set ( PostIdSet, SomeValueSet or something like that) or as a nullable type in .NET (PostId? or Nullable<Number>). If it's a nullable, the value won't be directly accessible from FoxPro and you have to use SetProperty()/GetProperty()), because generic types are not COM accessible.

The latter is usually a sign of a badly designed service and the regular .NET Web Service proxy can't actually navigate these. This is what ends up as object[] arrays, which can't be serialized by .NET (Xml Serializer doesn't serialize non-specific objects).

Why don't you post a screen shot of the .NET type info that is actually there in Reflector/ILSpy etc. For the object you can't access.

+++ Rick ---

© 1996-2019