C# Visual Studio WSDL import generates wrong classes - c#

I need to develop a web service, I received the WSDL (with HORRIBLE unintuitive field names), so I decided to import it as a Service Reference in Visual Studio 2015 to get the classes and the methods to call.
This is the WSDL (I'm sorry I'll need to use pastebin for the characters limit in the body of a question):
http://pastebin.com/B4pFH3jY
The generated code can be found here:
http://pastebin.com/Y9ehXQxy
When I try to build I get several errors:
public partial class Z_CA_WS_ARS_AFC_GET_SCH_CC has the same name of an interface, so I get error.
Lot of items argue about not having as parameter the interface (as it is considered the partial class)
I tried to rename the partial class, but I don't know in the remaining code where I should change and call the class or the interface. The names, as I previously said, don't really help.
When I import in Visual Studio I use the following (default) advanced settings, maybe it helps.
Is there any way to import the WSDL with no issues without asking for a new version (it seems correct to me)?
I even tried to use svcutil with no luck, maybe I used the wrong version.
Thanks for help.

Related

How to find derived class in Visual Studio 2017?

I don't have Resharper installed.. I want to see all subclasses inherited from IActionResult and there is no things like show derived classes in object browser and class view.
I try to install a extension TypeHierarchyViewer(https://marketplace.visualstudio.com/items?itemName=munyabe.TypeHierarchyViewer) but it is not working (even using the example List, just remains blank) .
So what should I do?
I use this function frequently developing java application using eclipse..It seems there is no out-of-box tool in VS2017 or I just missed some things??
(Go To Implementation says the symbol has no implementations)
(Same in class view)
I have searched many "solutions"(like Visual Studio: How do I show all classes inherited from a base class?) but not work or need other tools(or just see the doc?).
I want to see if there anyway to do it just using VS.
Before I thought VS was a very good IDE but I can't image it lacks so much basic functions...(so there is Resharper...)
And I find there is derived types but in Solution explorer:
But you can't input the class you want And if I input IActionResult in search box it will not find it(not in the my source and I don't implement it).
After trying..I find VS support it in solution explorer...
But it's hard to use...
I need to find some classes or interface in my source code related to the class or interface I want and use derived type and implements to find the it..
It looks like:
(I find a class and navigate to object, it lists all classes .Then I find ActionResult and choose implements find IActionResult, finally I can see all derived classes above... ...)
emmmmm
it seems there is no direct way using VS(although I can get all sub classes using solution explorer but it's too verbose...) to get the result I want.
Finally I choose to use dotpeek(I don't want to buy resharper because I just study ASP.net core not for work)
I open C:\Program Files\dotnet\sdk\NuGetFallbackFolder in dotpeek where the dependencies located.
Then using Hierarchies get the result.
feel a little disappointed about VS. Not so strong before I heared.
Thx for help. :)

Provide hint to IntelliSense that a partial class should not be modified

As of lately I'm using quite some code generation, usually in combination with partial classes. Basically the setup is as follows:
Partial class containing generated code. Some of this code will call partial methods. The code is re-generated a lot of time. The code generator is in some cases a custom tool.
Partial methods are manually implemented in a separate file.
The problem is that when I'm using Intellisense features like "generate method", they are for some reason generated in the file containing the generated code. Obviously I don't want that.
My question is: Is it possible to generate some hint that tells Intellisense it shouldn't touch certain 'cs' files (but instead the other partial class)?
Update
In retrospect I should have noted that I'm using a custom tool to generate the code. It's not a EF or a simple transformation; there's quite a bit of logic involved in the code generation. Also, it generates a complete namespace and class structure with partial classes. The 'root namespace' is found by extracting it from the csproj file and then using the folder structure to figure out the absolute namespace (it's similar to how Linq2sql does this).
The answer suggested by xanatos (thanks!) works: intellisense sorts its operation on the name, then alphabetically sorts on the name and then picks the first item in the list. This means that you can generate a zzzz.foo.cs which (albeit a bit ugly) will work just fine. I've just ran some experiments and found out that the feature find all references returns the order that VS appears to use. As it turns out, it works like this:
Say you have a custom tool that works on the filename foo.bar and transforms it into foo.cs. The custom tool will generate the content as string and pass it back to Visual studio (that's just how custom tools work...). The result will be in a file called foo.cs.
Now, I was quite surprised to found that Intellisense does not sort it as foo.cs but rather as foo.bar\foo.cs. In other words: regardless of how you name the 'cs' output in your custom tool, you have to rename the base file foo.bar to something like zoo.bar.
While that might be a workaround, I'm hesistant to accept it as the answer, because I would have to give files in my project strange names (names have meaning...). Also, some of my custom tools have dependencies on their filenames, so that will also get broken...
Therefore, I'm still open for suggestions on how to fix this properly.
From a simple test I've done in VS2013, it seems that Visual Studio 2013 adds the method to the "first" file he finds in the Solution Explorer. So you could simply add a .something.cs to your file-name, like MyClass.generated.cs vs MyClass.cs. Be aware that the VS2013 seems to be using the "full path", with path ordering based on name. So:
Z\MyClass.cs
comes after
MyClass.generated.cs
(and Intellisense will put code in MyClass.generated.cs) even while in the Solution Explorer all the folders are ordered first.
Full example:
A\MyClass.gen3.cs
MyClass.gen2.cs
Z\MyClass.gen1.cs
This should be the order as "seen" by the Intellisense, so it will put the new classes in A\MyClass.gen3.cs.
Assuming you're talking about the EF, I always change the template file (.tt) so the filename of the auto-generated file is [classname].model.cs. This means my partial file, which by convention is called [classname].cs is alphabetically first and always seems to get picked for auto-generation.
All you have to do is find/replace all the:
fileManager.StartNewFile(entity.Name + ".cs");
With:
fileManager.StartNewFile(entity.Name + ".model.cs");
There should be 3.
This has other benefits like auto-generated files are clearly marked in the filename.
I still have no idea why they didn't do this in the first place.
If you're not talking about the EF, the same trick of using the filename to order them should work.

learning public methods of a class

I'm learning a bit of C# and I know a bit of c++ right now.
When I want to learn about a class's public methods - I look in the header file in C++- which C# doesn't have. Where do I get a good summary of a class's public methods without having to look in the source file?
In the documentation, in Visual Studio using the object browser or IntelliSense or using reflection (either at runtime or using third-party tools).
There are few ways:
1) Read the documentation - .NET Framework class library or the appropriate one for used library.
2) Take a look at class in Class view
3) Use some metadata reading tool like ILDasm
4) The last in the list, but the most useful and most used is Intellisense
C# doesn't have header files, but byte code-compiled assemblies (i.e. exe and dll files) contain a section with metadata about namespace and namespace members, which is used by the runtime to discover types, methods, properties and so on. Also, Visual Studio uses it to offer its powerful intellisense.
Anyway, if you press F12 when cursor is on a method name, or any member (class, enumeration, ...), or you right-click there, Visual Studio will go to the definition of the whole member, and if such member has no source code in your machine, it will show metadata only:

Visual Studio Express 2013 - Create separate c# code file?

The VS 2013 Express forum doesn't seem to exist at Microsoft so I'd like to ask here..
I am using Microsoft VS Express 2013 to create a C# project. I'd like to be able to add a whatever.cs file to the project so that I can put extra functions there instead of in the default Program.cs file. Back in the old days, we could import code files in C by using a #include but C# in the Visual Studio doesn't seem to do this.
I have been able to successfully add a .cs file, create a class within it, and then instantiate the class and call it's methods from within Program.cs but I'd rather not have to instantiate a variable and have to call functions like something.MyFunction() just to execute some code that exists in another file.
Is this even possible? If not, does anybody know why? I always like the #include in C. You could keep things nice and neat.
Files added to a Visual C# project are automatically "included" in every other file within that namespace. You do not need a using statement unless you change the namespace. Because of this, there is no equivalent of the "#include" directive from C/C++.
Now to handle your use case. C# is inherently object-oriented. It is not expected that you create a million functions and call them individually (like you do in C). So, if you want to use multiple files (and you should!) you have a few options:
Create a normal class (as you have already done) and instantiate it to call its methods. This is the preferred method, and you should be able to come up with plenty of classes for your program that make sense.
Create a static class. These don't have to be instantiated (you access them like MyStaticClass.MyFunc(); ). These are often used as "helper" classes. In general, use sparingly as they are hard to unit test/dependency inject.
Mark your class as partial. This allows you to define the same class over multiple .cs files. Again, this should be used sparingly (see Jon Skeet's answer: https://stackoverflow.com/a/2895068/1783619)

how to handle redundant classes used in web services

I've started using some web services that have a staggering amount of redundancy when added as web services in Visual Studio 2012. Here are two WSDLs that demonstrate this:
http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCreateRQ.wsdl
http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCloseRQ.wsdl
These are services to create a new session and to close it, respectively. Each service has its own MessageHeader class, which in turn has a member that's from a MessageData class that's redefined in every generated proxy. There are others like this but I won't name them all.
This makes it difficult when I want to create a helper function that sets up my request and fills in all the common stuff in the envelope such as timestamps, authentication, etc. because Service1.MessageHeader is not the same type as Service2.MessageHeader. I've experimented with duck typing, but as far as I've seen the nested nature of this would prevent that approach.
Looking at the WSDL, these classes are all defined as being from the same namespaces. In other words, in both WSDLs, MessageHeader is defined as:
<xsd:import namespace="http://www.ebxml.org/namespaces/messageHeader" schemaLocation="msg-header-2_0.xsd"/>
...
<part name="header" element="eb:MessageHeader"/>
Is there some way to make VS understand that these are the same thing in both classes and somehow get it to separate them out as common to both? Or is it "a web service is an island"? I'd really rather not have to create separate code for every single type of web service I'll need, as there are far more than just these two. But every one of them uses these same classes.
I've thought about going in and hacking up the proxy classes by hand. But beyond my fear that this would make VS slip some gear because I'd messed up what it was doing behind the scenes that it never expected me to tinker with, I'd lose the whole auto-generation should something change in the WSDL that needed resyncing.
I've tried this both in C# and in Oxygene and run into the same issues. I imagine it'd be the same in other languages under VS. It seems related to how it understands WSDL.
Before anyone asks, I can't change anything about the actual web services. That is another company altogether, and not one that will be interested in redesigning their widely used system based on my whims.
I've found a potential solution to this, and it works in every way I can tell. But I'm open to criticisms or "a better way" (including a better way to do it from the GUI).
I've found that using the following command generates the proper "single unit" type of interface I want with all the types shared:
wsdl.exe /sharetypes /language:CS "http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCreateRQ.wsdl" "http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCloseRQ.wsdl" /o:"SabreWebServices.cs" /n:SabreWebServices
That creates a C# one. For Oxygene, I use:
wsdl.exe /sharetypes /language:OXYGENE "http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCreateRQ.wsdl" "http://webservices.sabre.com/wsdl/sabreXML1.0.00/usg/SessionCloseRQ.wsdl" /o:"SabreWebServices.pas" /n:SabreWebServices
FWIW, I used the wsdl from the "c:\Program Files\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools directory on my machine.
I added the resulting wrapper file to my application and it worked perfectly, if a bit differently than the wrappers created through Add Service Reference. I actually prefer the syntax this created a bit more. It also had the benefit of creating only the one file rather than numerous ones and not mucking with app.config. If you want to change the endpoint, you can just set the Url property of whichever service you instantiate.
I arrived at this solution at this post this via this post.

Categories

Resources