I am generating our Java web services WSDL and then importing it into our C# application each time I make a change. Every time this is done, the xs:choice
elements are regenerated but often with a different number depending on which one gets generated first. For example, lets say when I import the WSDL it generates ItemChoiceType1
and ItemChoiceType2
. The next time I import the WSDL (after changes) it will swi开发者_JS百科tch ItemChoiceType1
and ItemChoiceType2
so I have to recode the places I used those ItemChoiceType
s. Is there anyway to rename or specify a name for these constructs, or get them to generate the same way each time?
Thanks
So this object (myObject) has a property (myProperty) which has a type that may change at build time, and whose values are assigned from an Enum. Use this property setter function:
/// Set property value from Enum /// private static void propertySetter(Type typeNeeded, object targetObject, string propName, string fieldName) { var theDesiredValue = Enum.Parse(typeNeeded, fieldName);
Type t = targetObject.GetType();
PropertyInfo info = t.GetProperty(propName);
if ((info == null) || (!info.CanWrite))
return;
info.SetValue(targetObject, theDesiredValue, null);
return;
}
// usage propertySetter(myObject.myProperty.GetType(), myObject, "myProperty", "enumValue");
This is the default behavior of WSDL.EXE. Because the xs:choice elements are unnamed sequences, they are receiving a name generated by WSDL.EXE.
To my knowledge, there is not a workaround on the .NET side which will not be overridden if you re-import the WSDL.
If you have some control over your Java WSDL, you could specify complexTypes to wrap around the sequences and specify a name for each type. This may generate a more useful WSDL you could experiment with.
精彩评论