last day (15 days later) » 

5:34 PM
4
Q: Expose different type names (aliasing) from assembly

Dan LuggThis question is related to a previous, unanswered question of mine, as I'm still solving the same problem; this is about a different approach though. I'm currently consuming a third-party SOAP web service in a C# .NET project. Unfortunately, the generated client proxy classes and class members ...

 
You're asking if such a thing already exists? Or are you asking how one might go about creating such an attribute? Also, is using an attribute a critical part of the solution you are looking for, because, for example, you could always create a Qux class that inherits from qux, and then reflect the members by using properties with new names that pass values called from the old names.
 
@MarkBailey I'm asking if such a thing already exists. An attribute is not at all critical, per se, I was just hoping for something with the least LOC impact. Inheritance would work, however the original (poorly named) type is still exposed publicly, along with the members. Otherwise, yes, I'd just extend types and forward method calls.
I fear I might be venturing toward an X/Y problem situation; the linked question provides an initial proposal for how I'd have liked to solve the problem. Aliasing the names somewhere, without borking up the inheritance hierarchy would be excellent; whether that happens at the service consumption level, the assembly level, or elsewhere. Have a look at the original question @MarkBailey, if you have any insight.
 
I see, and I read the other post now too. I would expect, however, that even if such an Aliasing attribute or function does exist, it would probably still leave visible the old names that you don't want, so that you have your original and your alias. I suppose I do have some comments and an idea that I will post to the other question, since it addresses that more general inquery.
 
@MarkBailey Great! I look forward to your input. Attacking it at the service consumption level would be far better; I would assume there must be a way to perform a transformation on the WSDL, yielding different class names which map back to the appropriate service types/operations. This approach, assembly-level aliasing, is far more "extreme", and I'd rather not venture down this path for this problem (though, knowing it's possible or not never hurts)
 
After looking into this, the answer I posted below is significantly simpler and easier than what I had been considering. I have tested it now too, and it works the way I had hoped. I hope it works for your situation too.
 
5:35 PM
Hey @MarkBailey, I know this sounds stupid, but could you move your answer on this question over to the other one?
0
Q: Auto-alias generated SOAP proxies

Dan LuggI'm currently preparing to consume a SOAP web service in a .NET project (C#), however the naming conventions used for the service types and operations are pretty bad not consistent with the naming conventions typical to C# .NET projects. My question, essentially: is there a way to auto-alias the...

^^ It's far more applicable to that question than the one about assembly aliasing.
 
Yeah, I was kind of looking at a different way I guess.
I'd be happy to.
Does this work for you?
I was pretty excited to find it.
 
@MarkBailey I'm about to implement it, to give it a shot.
Just so I'm clear, I'm going to refactor (rename) the generated classes from qux to Qux, and then add that attribute with TypeName = "qux", correct?
 
Yeah, just change the name, and click the little box that says "Rename qux to Qux" to change it everywhere. And then adding that TypeName parameter in XmlType makes it as if that was the name when the SOAP XML is built.
I just tried it with one field on a service I'm using to make sure it works. From the description, it sounds like exactly what you want.
The only hitch would be if there service gets updated a lot, and you have to update the reference. It would be super cool if the update preserved those changes, but I doubt that it would. So you would want to keep a copy of your edited Reference.cs and do a merge with the updated version in that situation.
OR... there's this other thing... which I think would probably be a lot more difficulty than it's worth, over-engineering: SchemaImporterExtension
 
5:53 PM
@MarkBailey Yea, that was my concern; just because we might look at re-deploying some things internally, and rather than pass around the client library assembly, we'd just regenerate them, and end up losing the changes.
@MarkBailey I was looking at that.
I'm actually thinking that might be my best bet. If I can automate the process of mapping the original type/member names to aliases, at the time of service generation, then I can be certain that by at least passing that around, the SchemaImporterExtension, that all the built service references will be intact.
I'm extremely surprised that we're still using Svcutil.exe these days; I figured MS would have superseded it with T4 long ago; similar to how Entity Framework is implemented.
 
I'd definitely be interested in hearing how it goes if you try it with SchemaImporterExtension.
It definitely seems like an interesting approach, especially if the service will probably get updated frequently, and if the changes are of a pretty generic nature, like casing.
 
@MarkBailey Yea, I was just hoping there'd be something a hell of a lot easier; like an XSL transformation or something on the WSDL. That itself wouldn't work, but something simple like that.
 
@DanLugg That's exactly the sort of thing I was thinking at first. The idea was to prop up a thin service layer in front of theirs which presents the names that you want, and wraps the output with a class that runs a transform, and then the transform is all that you maintain, other than adding new fields to the interface layer. But as I started fleshing out the idea, I realized that the infrastructure around that was becoming a pain in the butt. And then I happened on the XmlType thing.
 
@MarkBailey Yea, that's exactly what I've been looking for.
<type old="oldClassName" new="NewClassName">
    <method old="oldMethodNameA" new="NewMethodNameA" />
    <method old="oldMethodNameB" new="NewMethodNameB" />
    <method old="oldMethodNameC" new="NewMethodNameC" />
</type>
^^ A way to map that basically.
So I'd maintain the mapping, and the WSDL URI, and that's it.
 
6:13 PM
@DanLugg Yeah. I see what you mean, but every way I turned the idea, using the C# web service technology that I'm familiar with anyway, I still end up writing the NewMethodName part not as a simple mapping, but as actually making the service itself. So you end up with exactly the sort of complication that you are trying to avoid with Wrappers.
 
I'll have to figure out how to implement that via SchemaImporterExtension
If possible, of course. I had tried to implement a different type of extension; something that gets in the middle of the WSDL => client proxy generation process, only to find that I couldn't rename anything -- the properties were all write-only.
It was based on another answer somewhere on SO; I'm pretty certain it wasn't SchemaImporterExtension (I'm hoping it wasn't)
 
@DanLugg So you'll try to use the extension to add the XmlTypeAttribute with the TypeName parameter in the auto-gen code?
 
@MarkBailey Yea, I'm going to have a look at the SchemaImporterExtension right now, but your answer will definitely be a backup.
Definite +1 on the answer; I'll probably accept it unless someone walks buy with a copy/paste/freedom approach ;-)
Add the SchemaImporterExtension bit to your answer; I'll mark it when either of them work.
 
Good plan.
And Good luck on this by the way.
 
Thanks a bunch. I'll keep this window floating; let you know what happens in a bit
 

last day (15 days later) »