How to use proxy class generated by WSDL in web service? - c#

Disclaimer: My experience/knowledge of web services is very limited.
There is an existing web service WSDL that I have reverse engineered with wsdl.exe to create a C# proxy class.
Using Visual Studio 2008 I created a default web service template.
How do I reference the generated proxy class so that it will work in the web service?
For example -> calling http://localhost/webservice/service.asmx?WSDL will return the details from the proxy class.

First of all, you should not be using ASMX web services. Microsoft now considers them to be "legacy technology", and suggests that all new development of web service clients or services be done using WCF. Don't start off at a disadvantage.
Secondly, the normal way to make use of a WSDL is to use the "Add Web Reference" command in Visual Studio ("Add Service Reference" if you were using WCF). This generates the proxy classes for you and adds them to your project.
I'm not sure from your question that this is what you want, since you first talk about the WSDL, but then talk about a "default web service template". What do you mean to do with the "default web service template"?
Try using the svcutil.exe program (not WSDL.EXE) as follows:
svcutil YourWsdl.WSDL /language:C# /d:subdirectory
This should produce a number of files in the subdirectory. Take a look at the .cs files, one of which will contain an interface which is the service contract. That is the interface that your service must implement. Look at your "default" WCF service application and you'll see that it does the same thing - produces an interface that is implemented by the service.

Related

ASMX web service shared between projects

I have an ASMX web service which is being called using Soap protocol. The service is using request / response types from one of our shared projects.
The project that consumes this service is also using the shared project. Now, I want that the reference that's been used in the project for that service should reuse the types being used in the shared project.
If that is not possible then can we inherit the service from an interface and then the wsdl tool can generate the implementation of the interface by inheriting from required classes?
Will WCF be an alternative?

How to generate proxy class from WSDL in case of webservice

suppose when i have only wsdl file then how can i create proxy class just to call webservice various method. how webservice related all class and its property & method will be exposed in my c# apps. can anyone help guiding me. thanks
You would need to use the ServiceModel Metadata Utility Tool, or Visual Studio's Add Service Reference Dialog in order to generate a client proxy for the service with which you want to communicate. The generated proxy will provide classes that abstract the service contract, and you can program your client applications to interact with these classes.
There is an utility, it shipps with Visual Studio (since 2005, I think), called wsdl.exe
It's commandline, and can be used to generate proxy.
You can use WSDL.exe tool using command line.
i.e. WseWsdl3 WSDLPath /out:MyProxyClass.cs
if WseWsdl3.exe is unable to create the proxy class, there is still a way.
If you can run your service as a regular ASP.NET web application in IIS, it creates temporary ASP.NET files where the proxy class is nicely generated for you.
You can find it in folder:
C:\Windows\Microsoft.NET\Framework\vMAJOR.MINOR.BUILD\Temporary
ASP.NET Files\YOUR_WEB_APP.
There are some subfolders with random names, go to most recent one and look something like "App_WebReferences.XXXX.0.cs".

Consuming webservice having WSDL and XSD files

We've requested a company to write a webservice that we can use to get some information.They have sent us WSDL and XSD files. Could you please tell me how I can use these files to query data?
I can do it easily if I have a link to a webservice. I just provide the link and Visual Studio generates web reference for me. After that I can use that reference just like a normal class. In this case I have no link. Just above mentioned files. Thank you.
You can create a proxy (add service reference in visual studio) from a wsdl file. You can read about svcutil at http://msdn.microsoft.com/en-us/library/aa347733.aspx, but VS2010 allow you to put a wsdl file on adress when adding service reference.
VS2010 can't create a web service reference from some WSDLs. Have
to write custom wrapper for those. OR edit your WSDL in a way so
VS can consume it. For example it may be ok for you to remove web
service method references for the methods that you are not planning to
use if those references create trouble for you.
Unless you're stuck with .NET 2.0, you should not use ASMX web service technology.
You should use "Add Service Reference" and point it to the WSDL on disk. It will create a set of "proxy" classes with methods that you can call just as though it were a "normal" class.
See "How to Consume a Web Service" for a walkthrough with example.
Use WSDL.EXE utility to generate a Web Service proxy from WSDL.
e.g.
wsdl /language:CS /n:"Microsoft.SqlServer.ReportingServices2010" http://<Server
Name>/reportserver/reportservice2010.asmx?wsdl
check this for Creating and Consuming .NET Web Services in 5 Easy Steps Article and then Creating the Web Service Proxy
Ref:
WSDL and consume web service
consume non .NET webservice through WSDL file
How to use a WSDL

WSDL2REST - is there a C# version? (convert SOAP to RESTful web service)

converting a WSDL to a REST web service, Is there a C# version of this library?
http://wsdl2rest.sourceforge.net/
I was wondering if you really need a library for this? I mean as long as you have the WSDL you can create a service using the svcutil and decorate the methods with WebInvoke and WebGet also specifying the method (POST/GET/PUT) and the UrlTemplate. The methods would also have return types and input params based on your current wsdl.
I haven't tried it but I've been reading on the issue as my current project requires me to do so when I get that stage of our development effort...
Here are some sources:
How to use a WSDL file to create a WCF service (not make a call)
"Reverse" WCF Service (Building a server from a client definition)
How to use a WSDL File to create a WCF Proxy?
and so forth...

Can I generate proxy objects for WCF service library using scriptmanager?

I have used the AJAX Enabled WCF Service template from within a web application. By adding a Service reference to the scriptmanager, some client objects are generated allowing me to easily consume the service. My question is can I do anything like that when I use a WCF Service Library? I added the project to my solution and in my web app I added a service reference to the service. This is where I get a bit stuck. What do I do now to allow consuming the service from the client.
So, just to consume wcf service, you have to use "svcutil" app from VS pack to generate o proxy class, which is very simple in usage.

Categories