adding multiple wcf service references in the same name space - visual-studio-2010

I have 8 wcf services, would like to have them in the same namespace when I add in the visual studio. I tried Service references -> Add Service Reference but every one creating their names space. Please let me know if you need more information !
thanks !

You can't control the namespace from visual studio. However you can use wsdl.exe to generate the proxy/service reference by hand:
wsdl.exe msdn
Use the /namespace parameter to generate in a specific namespace:
/n[amespace]:namespace Specifies the namespace for the generated
proxy or template. The default namespace is the global namespace. When
using the /parameters option, this value is the element
and contains a string. This element must be in the parameters file.

Related

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!

Need to set envirionment variable when using Azure Key-Vault Connected Service in Visual Studio?

When creating a .Net Core application in Visual Studio 2019, I selected the Key Vault option in Connected Services. This documentation page explains what is changed inside the project. Part of that change is adding an envirionment variable:
ASPNETCORE_HOSTINGSTARTUP__KEYVAULT__CONFIGURATIONVAULT
After adding the connected service you still have to call config.AddAzureKeyVault using ConfigureAppConfiguration in BuildWebHost yourself. In the same documentation they use a hardcoded endpoint. I cannot find anywhere where the variable is used. So where and how is this variable used?
So where and how is this variable used?
Actually, when you refer to the tutorial, the keyVaultEndpoint could easily get vaule from GetKeyVaultEndpoint. So you do not need the launchsettings.json to set variable.
If you want to use launchsettings.json, you could use the following code to get keyVaultEndpoint.
In Program.cs:
var keyVaultEndpoint = Environment.GetEnvironmentVariable("ASPNETCORE_HOSTINGSTARTUP__KEYVAULT__CONFIGURATIONVAULT");
In launchsettings.json:
{
"environmentVariables": {
"ASPNETCORE_HOSTINGSTARTUP__KEYVAULT__CONFIGURATIONENABLED": "true",
"ASPNETCORE_HOSTINGSTARTUP__KEYVAULT__CONFIGURATIONVAULT": "https://yourkeyvaultname.vault.azure.net/"
}
}
You could refer to this article to use multiple environments in ASP.NET Core.

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.

WCF shared types in WSDL

I have to use several separate webservices from the same provider. Basicly every function has its own service (wsdl). For interop every wsdl has references for shared types (ex: xs:import namespace="http://generic.type.com" />).
Adding Service Referances in VS will prefix the service namespace to these types.
Adding two services will generate two separate but identical class:
var context = new Service1.GenericContext();
var contex2 = new Service2.GenericContext();
How can I map/cast these together? I have 20+ services like this.
Tried NamespaceMappings in Reference.svcmap, but faild. I don't know what TargetNamespace and ClrNamespace to use.
ty!
Instead of adding service references you should use svcutil.exe to generate one service proxy file for the endpoints all together.
All service proxy classes are then together in the same namespace you specify with the command line switch /n.
The svcutil.exe call has many parameters then. So I recommend you store it in a batch file or even more comfortable: Place the command call under Build Events in Visual Studio into "Pre-build event command line".
Here is the svcutil call for my client which puts all proxy classes together in ServiceProxy.cs. Most likely you have to modify the path to svcutil.exe and of course the service URLs:
"%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0A\bin\svcutil.exe" /noLogo /noConfig /out:"$(ProjectDir)ServiceProxy.cs" /t:code /i /l:cs /tcv:Version35 /ser:DataContractSerializer /ct:System.Collections.Generic.List`1 /n:*,Oe.Corporate.CRMFacade.Service.Test http://localhost:3615/Client010/MasterDataService.svc http://localhost:3615/Client010/BusinessPartnerService.svc http://localhost:3615/Client010/MarketingAttrService.svc http://localhost:3615/Client010/ProductTransactionService.svc http://localhost:3615/Client010/ProductDataService.svc http://localhost:3615/Client010/ActivityManagementService.svc http://localhost:3615/Client010/PromotionService.svc
UPDATE:
I forgot to mention that the pre-build event will fail unless you add this to the bottom of your .csproj file right above the closing Project element:
<Target Name="PreBuildEvent" Condition="'$(PreBuildEvent)'!=''" DependsOnTargets="$(PreBuildEventDependsOn)">
<Exec WorkingDirectory="$(OutDir)" Command="$(PreBuildEvent)" ContinueOnError="true" />
</Target>

Resources