Error adding a service reference to Visual Studio via WSDL - visual-studio

I have been given a WSDL with all the method requests and responses, and all the objects I'll need to use for creating a few web methods.
I've successfully added the WSDL as a "service reference" and I can see the methods and structures and can instantiate them. It all seems to be there. But, I have a problem: the project won't build after I add the WSDL. Here's the error message I am getting when Visual Studio tries to compile Reference.cs:
"Error 2 The type name 'ServiceReference1' does not exist in the type
'WSPELab.WSPELab' C:\Users\JJ\Documents\Visual Studio
2008\Projects\WSPELab\WSPELab\Service
References\ServiceReference1\Reference.cs 21 111 WSPELabSLN
Is it possible that I am receiving this error message because of a namespace error on my part?
Finally, one additional question: With the WSDL added, can I use the structures it contains directly? Or are they just "listings" for me to implement?

A WSDL is a machine-readable file that describes the methods and types exposed by a web service. Many IDEs, including Eclipse and Visual Studio, can import these and create programming language classes that match the definitions given in the WSDL.
For example, importing a WSDL in a Visual Studio C# project will create a Reference.cs file that contains these definitions. You have to instantiate and call these definitions the same as you do for any classes.
var webServiceReference = new WsdlNamespace.ClassDefinedInWsdl();
WsdlNamespace.ParamClassDefinedInWsdl dataToGet;
WsdlNamespace.ReturnCodeTypeDefinedInWsdl retCode = webServiceReference.MethodDefinedInWsdl("params expected by method", out dataToGet);
if (retCode == WsdlNamespace.ReturnCodeValueMeaningAllIsWell)
{
// use properties of dataToGet
}
Giving any more detail would require showing us the actual WSDL.

Related

Bridge RESO OData API

Im trying to use the OData Connected Service in Visual Studio to connect to a OData Feed in Bridge (RESO Feed).
However, If I try and pull the metadata directly from a URL, it has errors Adding OData Connected Service to the project failed: Could not get CLR type name for EDM type 'memberMediaEnums.ResourceName'
So I went ahead and downloaded the XML file and tweaked it to get rid of the errors and warnings. This includes Removing Entity references with no parents and removing attributes that were not supported like Precision.
Once its all loaded and the reference file is created I tried pulling data. The endpoint works and data is retrieved, but it is not thrown into the object as i would expect.
IEnumerable<Property> properties= await context.Property.ExecuteAsync();
foreach (var property in properties) //Errors trying to make a property
{
Console.WriteLine("{0} {1}", property.YearBuilt, property.ListPrice);
}
When I try and loop over the object I get this error:
The context URI 'https://api.bridgedataoutput.com/api/v2/OData/imls2/$metadata#Property' is not valid for the expected payload kind 'Resource'.
Where I am confused, is in the name Resource There is no object or entity in the Reference file or in the XML scheme that references that word. I'm not sure if its coming from OData services or the reference file it created. The call stack does not contain anything but the exact line of the loop.
Any insights would be helpful but i know its a long shot. Let me know if I need to provide more details.
Thanks

Visual Studio 2019 - Connected Service Reference - OpenAPI is generating duplicate types

I am trying to generate an OpenApi service reference in Visual Studio 2019. .Net 5.0.
Right clicking project >Add>Connected Services>+ Service References
I am using NetDocs api "https://api.vault.netvoyage.com/v2/swagger/docs/v2".
Result: I get generated c# client code but it is duplicating the types with the errors below.
Severity Code Description Project File Line Suppression State
Error CS0102 The type 'v2Client' already contains a definition for '_settings' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4941 Active
Error CS0579 Duplicate 'System.CodeDom.Compiler.GeneratedCode' attribute OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4936 Active
Error CS0102 The type 'v2Client' already contains a definition for '_baseUrl' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4939 Active
Error CS0102 The type 'v2Client' already contains a definition for '_httpClient' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4940 Active
Is there a way I can get this to work with the connector way without the duplicates? Or even cli? Any suggestions on why it is creating the duplicates?
I had the same issue, it turns out the code generation didn't like enpoints with an underscore in its operationId. Lucky for me, the service I was consuming was also part of our code, so I could just go to the Swagger configuration in the API side and change the CustomOperationIds setting.
I downloaded and use NSwagStudio to generate the client code and did not have the same issue that the Visual Studio connector had when generating the code.
https://github.com/RicoSuter/NSwag/wiki/NSwagStudio
It is actually caused by this option
OperationGenerationMode:MultipleClientsFromOperationId
MultipleClientsFromOperationId : Multiple clients from the Swagger operation ID in the form '{controller}_{action}'
However, if your classname is set as a static name, it will cause an error like you have.
The correct solution should be change the classname to something like
ClassName="{controller}ServiceClient"
So it will generate different classes.

Adding WSDL service reference to VS fail because generated xsd file contains illegal character for TFS

I have a solution that is on TFS. I'm trying to add a WSDL as service reference to it.
The WSDL's URL looks like this: ".../ws/soap;auth=..."
When adding the reference, VS will generate all the required xsd files and the xsd files name would use the URL as its name. When generating it, TFS will try to automatically add the files, and at this point it will detect that I have a .xsd files with illegal character ";" as its name and then the whole service reference generation just failed and stopped.
I have tried adding the wsdl to a solution that is not bound to TFS and it works just fine.
Any workaround? How do I add the wsdl as service reference to my solution if the generated xsd contains illegal character that TFS won't accept?
You can use svcutil to generate proxy classes,svcutil is a .NET tool that retrieves metadata from a web service on a network location or from a WSDL file, and generates a WCF class containing client proxy methods that access the web service operations.
You can use this tool on the command-line interface of VS:
enter image description here
Executing the above command will generate the a proxy class and configuration file on disk D.Then add these two files to your project:
enter image description here
Here's a link about svcutil:
https://learn.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-svcutil-guide?tabs=dotnetsvcutil2x
Can you try adding a new class to your project, and copy the contents from the generated proxy class file through svcutil (link below, just in case). This way, I believe, you would be able to bypass the illegal characters in XSD.
You would be able to generate proxy class through Visual Studio Command Prompt using SvcUtil command
HTH!

Server Error with the griffin.mvccontrib package in asp.net

In order to be able to translate my data annotations in my model with a resource file, I saw that many people recommend the solution offered by jgauffin.
However, when I follow the localization tutorial my project cannot launch.
The problematic code is this one, which is supposed to go in the Global.asax.cs file:
ModelValidatorProviders.Providers.Add(
new LocalizedModelValidatorProvider(stringProvider)
);
It says that the LocalizedModelValidatorProvider constructor does not take any arguments, which is also shown by other tutorials.
But when I change the line like this:
ModelValidatorProviders.Providers.Add(
new LocalizedModelValidatorProvider()
);
I get the following error in the browser:
Attempted to access an element as a type incompatible with the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
The griffin.mvccontrib packages were installed with NuGet under Visual Studio 2012. Any idea what I am doing wrong ?
You might find this link helpful
Here is how I did the registration in the above link:
ResourceStringProvider myResouceFile = new ResourceStringProvider(ModelsResources.ResourceManager);
//ModelsResources is my resource file generated class
GriffinStringsProvider griffinStringsProvider = new GriffinStringsProvider(myResouceFile);
ValidationMessageProviders.Clear();
ValidationMessageProviders.Add(griffinStringsProvider);
ModelMetadataProviders.Current = new LocalizedModelMetadataProvider(myResouceFile);
ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new LocalizedModelValidatorProvider());
Make sure you are including the right assemblies
using System.Resources;
using Griffin.MvcContrib.Localization;
using Griffin.MvcContrib.Localization.ValidationMessages;
Also the assembly for your Resource file.

Magento API not working with wsdl.exe but works with Soap UI

I'm trying to integrate Magento 1.7 with a C# application.
When I tried to use the "Add Service Reference" function in Visual Studio, it finds the service and all the operations but when I click OK, it doesn't generate anything. i.e. the Reference.cs file is almost empty (only has one line with namespace).
I tried using wsdl.exe to generate the proxy in command prompt and I got the following error:
R2718: A wsdl:binding in a DESCRIPTION MUST have the same set of wsdl:operations as the wsdl:portType to which it refers.
- Operation 'catalogProductAttributeRemove' on portType 'Mage_Api_Model_Server_Wsi_HandlerPortType' from namespace 'urn:Magento' has no matching binding.
For more details on the WS-I Basic Profile v1.1, see the specification
at http://www.ws-i.org/Profiles/BasicProfile-1.1.html.
Error: Unable to import binding 'Mage_Api_Model_Server_Wsi_HandlerBinding' from namespace 'urn:Magento'.
- The operation 'catalogProductAttributeRemove' on portType 'Mage_Api_Model_Server_Wsi_HandlerPortType' from namespace 'urn:Magento' had the following syntax
error: The operation has no matching binding. Check if the operation, input and output names in the Binding section match with the corresponding names in the PortType section.
I then tried using Soap UI to load the same wsdl and it works fine. The proxy was generated and I can make calls without any problems.
The original wsdl file is here: https://gist.github.com/4514723
except I have replaced line 6297 with an example url.
So my questsion is why was Soap UI able to generate the proxies and making calls without any problems but Visual Studio can't? How can I fix it?
See Generate a Web Service Client in WS-I compliance mode .
You will need to modify your Magento code to correct the WS-I compliant WSDL definition in app\code\core\Mage\Catalog\etc\wsi.xml.
The SOAP UI is probably more tolerant of mistakes in WSDLs compared to other .NET/Java tooling.

Resources