I've recently had an issue where I have a web service asmx file where clients can access the wsdl through an https address, such as https://example.address/webservice.asmx?wsdl. When adding a web reference to Visual Studio, it tries to access http://example.address/webservice.asmx?wsdl — which returns a 404 error as the server is not configured to allow non-secured access. This also occurs in SSIS when adding a web service reference, or web service task (even when a certificate is added).
In Visual Studio, I'm also able to add it as a service reference which generally works (except for double[] being changed to ArrayOfDouble, etc.), but it doesn't appear that service references are an option in the Visual Studio provided within SSIS.
I've searched around for this quite a bit and there seems to be no easy solution to force https to be used. Instead, I'm wondering if there is a way to import wsdl references into a project manually without adding it as a web reference (just to add the request methods). That way I can create my own https SoapClient that uses these methods without the web reference issue.
You can generate client proxy classes by using the wsdl.exe
Web Services Description Language Tool (Wsdl.exe)
wsdl /out:myProxyClass.cs https://example.address/webservice.asmx?wsdl
wsdl.exe can be used either by opening the Developer Command Prompt, or executing it from the folder it resides in: ProgramFiles/Microsoft SDKs\Windows\v7.0A\Bin\wsdl.exe
You can generate client proxy classes by using the svcutil.exe
svcutil.exe [/t:code] <metadataDocumentPath>* | <url>* | <epr>
ServiceModel Metadata Utility Tool
The svcutil.exe is like a next generation of wsdl.exe utility. Svcutil allows you to generate proxies for both - web services and WCF services.
Svcutil supports DISCO protocol along with WS-Metadata Exchange protocol, which is an interopable standart of SOA.
In some cases both utilities wasn't generate client proxy, therefore you will need to do two things to get the WSDL you need:
Download all of the files that are referenced; these will be either <?include> directives or <wsdl:import> tags found within the other XMLs file, which pull in a second one. You need to check each new file, as there are often second and third level imports. Put everything into one folder.
Edit all of those include references to remove the URLs and just use local file references.
Once that's done, you can generate client proxy from local files by next command
svcutil *.wsdl *.xsd /l:C#
You can download the WSDL file by using disco.exe located in the same folder as wsdl.exe to download your web service wsdl file.
Web Services Discovery Tool (Disco.exe)
disco http://www.proseware.com/prosewareWebservice.disco /o:"c:\folder"
And then you can go on and use Wsdl.exe to generate your proxy class
Related
I need to add a service reference using a WSDL supplied by a customer. The WSDL contains references to their WCF web service which I cannot see from my development machine. The reference is resolvable on our acceptance environment but I cannot install Visual Studio there.
I thought the point of the WSDL was that it contained all the information for VS to generate the classes necessary to talk to the WS (even without direct access to the WS).
Have have 2 questions:
Is it possible to add this WSDL to my C# project without visibility to their WS
otherwise
Is it possible to generate the classes from the environment that does have direct access to the WS, without installing VS? Maybe by just installing the svcutil.exe (but I imagine this to0l will also require VS)
I am using SvcUtil.exe to generate IClassName.cs file from wsdl file and that is working fine. My problem is that I do not know how to generate ClassName.svc file using command arguments for SvcUtil.exe.
After running the SvcUtil.exe I would like to get WCF service like when you created from Visual Studio Wizard containing all classes *.svc, *.cs, and interface.
Thank You,
Skrch
First of all to generate proxy class we need to have our service up and running. So before using this utility make sure that your service is running without any issue.
After verifying the service status go to Visual Studio Command Prompt and run the following command.
svcutil http://localhost/MyService/ClassName.svc /Language=c#
/t:Code /out:ClassNameProxy.cs /config:ClassNameProxy.config
In above command you should replace the service URL ( http://localhost/MyService/Service1.svc) with the URL of your service.
Since my services is developed in c#.net so I choose to generate the proxies in the same language by using /Language=c# flag.
/t:code will specify that the out put should be generated as code.
/out:ClassNameProxy.cs /config:ClassNameProxy.config parameters will tell the utility to name the files as specified in these parameter values.
After you run the command, tool will generate the output file and config file.
After that just include the ClassNameProxy.cs file into your project and open the ClassNameProxy.config file and copy the entries to your web.config file.
You may also need to update the ClassNameProxy.vb file and update the namespace as per the one that you are using in your project. After that you can easily reference the service in your code and call the operations.
Some examples from tool how it can be used
svcutil http://service/metadataEndpoint
- Generate client code from a running service or online metadata documents.
svcutil *.wsdl *.xsd /language:C#
- Generate client code from local metadata documents.
svcutil /dconly *.xsd /language:VB
- Generate Data Contract types in VisualBasic from local schema documents.
svcutil /t:metadata http://service/metadataEndpoint
- Download metadata documents from running services
svcutil myAssembly.dll
- Generate metadata documents for Service Contracts and associated types in
an assembly
svcutil myServiceHost.exe /serviceName:myServiceName
- Generate metadata documents for a service, and all associated Service
Contracts and data types in an assembly
svcutil myServiceHost.exe /dconly
- Generate metadata documents for data types in an assembly
svcutil /validate /serviceName:myServiceName myServiceHost.exe
- Verify service hosting
svcutil /t:xmlserializer myContractLibrary.exe
- Generate serialization types for XmlSerializer types used by any Service
Contracts in the assembly
For anyone still looking for the answer and could not get the 2012 version working, Visual Studio 2015 and .Net 4.5 have updated the svcutil.exe tool to use /serviceContract switch to generate a class that can then be implemented as a .svc service.
You may need to provide /syncOnly /wrapped /messageContract switches as well depending on the original XSD's
Svcutil.exe generates the service client proxy based on the Web Service Description Language (WSDL) from the service.
Open the visual studio command prompt and run the command
svcutil http://localhost/MyService/Service.svc /Language=c# /t:Code /out:C:\Service\ServiceProxy.cs /config:C:\Service\ServiceProxy.config
it generates two files in C:\Service folder, the proxy file and config file,
More details here.
I think the .NET 4.5 Contract First Tool, integrated into Visual Studio 2012 as a build task, will help you generate the service files you need.
Service contracts often need to be created from existing services. In .NET Framework 4.5, data contract classes can be created automatically from existing services using the contract-first tool. To use the contract-first tool, the XML schema definition file (XSD) must be downloaded locally; the tool cannot import remote data contracts via HTTP.
http://msdn.microsoft.com/en-us/library/hh674270(v=vs.110).aspx
i got a folder with a WSDL file (and all the xsd files related to it) but i can't seem to generate a web service from it using the "Add service reference" option in VS2013 (also tried in 2008 just to test). I'm using .net 4.0.
i get multiple error such as:
Custom tool error: The global type ('WarningType') has been defined in both
'file:///D:/WSDL/AMA/2011Y/chameleon/AMA_CommonTypes.xsd' and
'file:///D:/WSDL/IATA/2010.1/chameleon/IATA_CommonTypes.xsd'.
They are different at './simpleContent/extension/#base'.
so, i was advised to use "Add Web reference" tool.
this works for some reason. i get no errors now.
But, the problem is that i found out that a web reference do not support WS-Security /WS-Adressing
(someone wrote this as a comment in how to add SOAP Security header) and i MUST specify in the header those elements.
Also, i keep reading not to use a web reference since this is an old technology.
So, does anyone know how to solve the errors I'm getting ?
There are multiple tools that generate service proxy objects. Apart from using Add Service Reference you can use command line tool svcutil.exe which is included as part of the visual studios installation for generating service objects.
Here is how to do this
http://msdn.microsoft.com/en-us/library/ff623148.aspx
This alternative command line approach will help you resolve issue related to WS-Security / WS-Adressing.
I have to use a ColdFusion webservice in my project. I have
added the service reference in my project and it was successfully loaded, but
service is not accessible in my web application.
What I have done is let's say I have a url http://www.server/service.cfc?wsdl - I have added the above service reference and given the service reference name as MyServiceReference.
When I am accessing MyServiceReference in my class file it is not accessible.
I had a similar issue this week when consuming a Coldfusion webservice. To solve it I suggest you can:
1. Consume the WS using old 'Add Web Reference' (like .NET 2.0) instead of using 'Add Service Reference'
In my case, the problem was the webservice's methods were generated with return void and they hadn't had parameters, but when I added the service using this technique the proxies were correctly generated. This post has helped me.
2. Try using WSDL.exe from Visual Studio Developer Command Tools to see if there is an error with service description
If there is maybe you will not be able to generate proxies correctly and you should ask developers to correct the service.
The tool I mentioned can be found at 'Start Menu\Programs\Microsoft Visual Studio 2012\Visual Studio Tools\Developer Command Prompt for VS2012' (also for VS2010).
In my case I've seen the following error:
"This web reference does not conform to WS-I Basic Profile v1.1.R2706:
A wsdl:binding in a DESCRIPTION MUST use the value of "literal" for the use attribute in all soapbind:body, soapbind:fault, soapbind:header and soapbind:headerfault elements."
Why would someone use SvcUtil.exe when Add Service Reference in VS.NET provides all the proxy classes you'll need?
Sometimes Add Service Reference in VS fails to create a useful proxy. Instead it gives you an empty Reference.cs details here and here file. I've created a series of bat files to call SvcUtil.exe to generate the proxy classes.
Both svcutil.exe & 'Add Service reference' will use the same proxy generation code underneath. Think of 'Add service reference' as a UI way to generate proxy where it pre-populates a set of switches that you will have to do in svcutil command line. For example when you add service reference in VS the UI lets you to reuse types from referenced assemblies, specify the kind of proxy to be generated (sync-async / task based etc). svcutil will also be useful if you want to automate service reference generation.