there is a odata webservice, i can get metadata from
http://service-uri.com/$metadata
which contains definition of all its model object,
is there any tools that i can use, to convert that metadata xml to data contract class in C#?
The WCF Data Services Client library can generate C# classes for you from the $metadata endpoint. These classes won't have the [DataContract] attribute, but you can use them with the rest of the client library to interact with the service.
To use this feature, download the latest "tools" installer for the client library, currently available here: http://www.microsoft.com/en-us/download/details.aspx?id=35840
(Note: If you want the latest stable bits of the client library, also run the following from the Package Manager Console window in Visual Studio: Install-Package Microsoft.Data.Services.Client)
Then, from within Visual Studio, you can right click on your project, and select "Add Service Reference". Here you can enter the $metadata URL of the service, and the corresponding classes will be generated, along with a DataServiceContext class you can use to interact with the service. For more info on querying the service, see this documentation: http://msdn.microsoft.com/en-us/library/dd673933.aspx
Or, if you want to generate the classes manually, you can use the DataSvcUtil.exe command line tool that comes with the tools installer. On my system, for example, that file is located at
C:\Program Files (x86)\Microsoft WCF Data Services\Current\bin\tools\DataSvcUtil.exe
For instructions on how to use this tool, take a look at this page: http://msdn.microsoft.com/en-us/library/dd756369.aspx
Related
Am trying to create a WCF project by following the walkthrough here ... http://msdn.microsoft.com/en-us/library/bb386386.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-3, but got stuck at the first steps.
Bad - VSE Windows Desktop does not have the WCF service library templates.
Good - VSE Web Developer does, so I set up the WCF project in VSE Web Developer
Bad - Cannot open the WCF project in VSE Windows Desktop
Good - Find out that you can copy templates from VSE Web Developer Folders to VSE Windows Desktop, and I do
Good - VSE Windows Desktop now has WCF service library templates, so I try to create a new WCF project. VSE seems to comply, sets up the project folder ... but then
Bad - ... throws the error ...
The project file '... WcfService1.csproj' cannot be opened.
There is a missing subtype.
Subtype:'{blah blah}' us unsupported by this installation.
I even tried turning it off and turning it on again.
What next?
As I mentioned in my comment, a WCF Service Library is nothing more than a class library - the WCF Service Library project template just has additional stuff to make it quicker to set up the project. You can do the exact same thing by creating a class library.
Go to File -> New Project on the menu. In the window that opens up, expand Visual C#, then select Windows and select Class Library from the list in the center, give it a name and then click OK.
You'll have to add the Interface and the config settings for the service, but you should be able to copy and paste from the article you're following. Once that is done, voila, you have a WCF Service Library.
Edited for more details
The only thing the WCF Service Library template gives you is a boilerplate for a WCF Service Library - that includes the .cs file for the service implementation, the .cs file for the service contract (interface) That the service implements and an app.config file that has the necessary <system.serviceModel> entries.
Sticking with the article you linked to in your original post, here's how to do this without the template.
Step 1 and 2. Follow what I had above - create the class library. VS will create the project and you will see a file named class1.cs. This will be your service class. Rename it to WCFServiceLibrary1.cs if you desire.
Next add an interface and name it IWCFServiceLibrary1. This will be your service contract. You will need to update the WCFServiceLibrary1.cs file and add : IWCFServiceLibrary1 after the public class WCFServiceLibrary1, so it looks like this:
public class WCFServiceLibrary1 : IWCFServiceLibrary1
In the interface, add the [ServiceContract] attribute above the interface, like this:
[ServiceContract]
public interface IWCFServiceLibrary1
You will also want to add a reference to System.ServiceModel and using System.ServiceModel to your class and interface.
Step 3 and 4. Copy the code in the article to the proper files.
Step 5: You can test the service by hitting F5 and running the WCFTestClient.
You should then be able to follow the rest of the article.
It takes a little longer this way, but you will also gain a better understanding of what the WCF Service Library is.
Expectation management - I was expected to go through all the steps in the walkthough, but they might not be necessary (which is implied in the answers given). So, I tried a bare-bones set up, described here ...
Is it possible to start exploring WCF using Visual Studio Express for Windows Desktop 2013?
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'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
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."