how to reference web service with wsdl file only - c#

I'm writing asp.net/c# project and need to call web services which other client provide. I've found that most people right click "service reference" to add url and use it. The thing is, I got .wsdl file only, is there any way to use it directly?
I've tried the solutions in here and they didn't work.
Thank you for answering.

Related

Adding and consuming web reference using wsdl definition in asp.net client

First let me say that I'm new to web services and though I have google'd and watched tutorials I"m still having issues figuring out why I cannot consume the service. I'm not exactly sure how to ask the question I'm trying to lay it out nicely. If I've missed some needed info I'll be happy to add it to the question. Thanks for your time.
I was given a service reference to consume of https://demo.cashlinc.com/IntegrationService/Service.svc to consume.
I then proceeded to perform the following steps from visual studio...
From the client (consumer) application RMB > Add Service Reference...
From the Add Service UI, Address: https://demo.cashlinc.com/IntegrationService/Service.svc?wsdl , namespace = DivDatService
The service reference structure is like this...
Now here is the part where I'm fumbling...
There is for example a method GetPaymentProfiles...now that I've added the web reference how do I call the method?

My First WCF Service and I'm Stuck

It took a good bit of trial and error, but I was finally able to host my WCF Service in IIS.
I can browse to the WSDL no problem, and see all of the different methods/attributes.
Now what? I need to use my service inside of another Web App. How do I do that?
I was able to use svcutil.exe to generate the *.cs and output.config files, add that to my web app, and add a reference to System.ServiceModel That worked fine.
BUT, I need to figure out how to use my service hosted in IIS.
In my web app I've added a web reference to the WSDL, but I can't figure out how to expose the methods/attributes.
I'm not ruling out the possibility that there's a better way to do this...so I'm open to suggestions.
Can anyone point me in the right direction?
Right click on the client project and click "Add Service Reference". Then put in the address of your WCF service and it will create the proxies and plumbing for you.
You can add Service Reference to your service. By doing this you don't need the svcutil.
Or you can use the .cs that svcutil generated for you.
http://msdn.microsoft.com/en-us/library/ms730144.aspx
Simply you have to use the class on your .cs file. Istantiate it and call wcf methods...

Consume web service in asp.net app from a class library

My team and I have a asp.net web forms application and are using several class libraries. In one of those libraries, we are trying to consume a web service. The web reference was added in the web app project and the appropriate references have been added. The app compiles. When attempting to consume said web service in the class library, the credentials don't seem to work, and the call fails. However, if we take the web service call out of the class library, and consume it within the web app, it works.
Any ideas why this is not working in the class library.
Double check your configuration file includes the correct information for the Web service.
Try changing the URL behavior to dynamic as well.
Also, as John stated, I'm assuming you're adding the service to the class library because you intend to use it from the library, as opposed to other areas of the Web application.
"the credentials don't seem to work, and the call fails"...can you give a small stack trace of the error?
Just to clarify, in my current project, we use WCF endpoints within a class library with bindings and credentials. The same can be done for a SOAP ASMX Web reference as you're attempting.
You can add a web service reference by doing the following steps:
right click on the project on the Solution Explorer
click Add Service Reference
click Advanced
you will find "Add Web Reference" at the end of the form
If you are adding the reference in application and then consuming it from class library... How you call the class library.. by adding reference and invoking the method of class library and then how you are accessing proxy from the class library you need to reference it... It seems to me a circular reference. Which shouldn't be compiled at first place... Are you describing your structure correctly???
It's always better to add a simple project with just web reference and then add the reference of this project on all the projects which requires it.
You can add a web service reference by doing the following steps:
right click on the project on the Solution Explorer
click Add Service Reference
click Advanced
you will find "Add Web Reference" at the end of the form
By #AMgdy 's solution,It'll auto generate a Reference.cs class.It defined all of method of webservices.
May be you called it wrong!!
Here is an example:
var serviceName = new ServiceName
{
Credentials = new NetworkCredential("Username", "Password", "Domain"),
Url = "Here you put the correct url of the web service if you published somewhere else"
};
serviceName.CallWebMethod();
make sure that you entered the correct Credential username and password and make sure the you published the webservice to a place you access it.
Have you defined any credential information in a config file in the web app? If so, the class library probably can't fetch them correctly. Just a guess though. And John Saunders is right. Seems a bit backwards reading your description of your apps structure.

Web Service deployment in IIS?

I started learning web services. I learnt about web services, UDDI, WSDL, SOAP etc. and architecture of web services. Visual Studio is running the service in local system successfully.
Then I deployed the entire folder of that web service in IIS wwwroot, and tested. Its running successfully.
But when I remove the other file from the wwwroot\webService1 folder (I left only service1.asmx and bin folder) then also service is running.
Here I see that only two file are used in ruuning the webservice one is .asmx and another one is webService.dll in bin folder.
I'm not able to understand where is SOAP, WSDL, namespace or other things, that are required to run web service.
Please clarify.
SOAP, WSDL, Namespace are all handled by IIS and ASP.NET. In your scenario, your web service endpoint is your asmx file (no .cs file required in your deployment), and the DLL in the bin folder contains the code that you wrote for your webservice (so it does something).
If you call up your webservice in a web browser, you should see your web methods listed out to test. IIS knows how to process *.asmx files to do this. If you click on one, you should see a sample form (if input parameters are expected) and a button. Again, IIS knows how to serve this out to you. When you click the button, IIS and ASP.NET handle the work of SOAPing your request, handling it with your code, and SOAPing the response back to you.
If you create a "test" project in Visual Studio, and set a web service reference that points to your deployed web service, Visual Studio will create a proxy class and pull in some additional code from it's discovery of the service. Try it. You should get at least: a WSDL which defines your web service, a file called reference.cs which contains the code that does the heavy lifting of calling your webservice (SOAPing the request from your application and unSOAPing from the response).
If you download a tool called Fiddler, you should be able to intercept and inspect the SOAP call to your web service.
Take a look at Web Services with ASP.NET for additional information.
There are no such 'files' at all. The asmx and dll files contain all of the code for the service. You can see some of that in the URLs that are requested for the SOAP/WSDL info.
I believe if you append ?WSDL after .asmx you will see the definitions.
Such as this example:
WSDL Example
I think these are protocols and does not require anything. IIS and the requesting applications understand these protocols.

Calling PHP Webservice from C# using supplied WSDL

I've been passed a WSDL from a third party. Their web service is PHP on Apache.
I can call its methods from within XMLSpy and Validwsdl.com. But cannot get my C#/Visual Studio project to build/validate the WSDL. When I add it to my project - it shows all of the methods and seems fine but won't build.
I've tried add web ref, add service ref, I've tried command line WSDL.exe. Nothing works. Should I be having to hack at their WSDL document? Do I need extra libraries/includes?
I don't understand why it's not working.
The WSDL is :-
http://www.gesundsolutions.com/epp/application/heiq.wsdl
Any Ideas?
Have you used the "Add Web Reference" from the menu in VS?
A simple and quick tutorial that shows you what is needed for communicating with a web service from elsewhere is this post on op0.com. Check it to find out what you're possibly missing.
Yes, just the WSDL is enough if you know the location of the web service. No, you should never change the WSDL, as that is the calling convention.

Categories