I am new to using web services. I am assigned a task in which I need to use a web service in my Windows app. This is the web service I would be using:
https://api.betfair.com/global/v3/BFGlobalService.wsdl
Now, I've learned how to add a web reference to this service, but I could not find a basic tutorial that could help me learn how to make an object of this web service and use the service as I want to.
Basicaly, what I need is to create an object from the above web service in my form, and to call it's methods. A C# code snippet would be great.
Can anyone give me some directions? I am working in Visual Studio 2008 and a C# Windows App.
Right click on References
select Add Service Reference
give the wsdl address in the address textbox
click Discover
Give a name for the namespace eg;- BFG
You can access the resources like BFG.MethodName() from you code
Related
I am new to web service developing. I am experimenting on creating a backend for an app (which by the way is a Windows 10 Universal App). What I am trying to do is very simple: I want my app to ask the service to do something, after which the service runs some code and returns something. In other words I want to call a method defined in the service, from my app.
I have found tons of guides on this but they all date back to the early 2000's and use technologies that are now deemed obsolete.
What I managed to do so far
I created a new Web Site (File->New->New Web Site) using the WCF service template (Visual C#, .Net framework 4), added a Web service ASMX to it (right click on project->Add->Add New Item->Web Service (ASMX) ), then I added some webmethods to the .cs file associated to the webservice.
[WebMethod]
public void MyVoidFunction() { //Do something }
Then, in my app, I added a service reference to the webservice (right click on references -> Add service reference -> insert the localhost address up to .asmx -> click Go -> assign a namespace -> click ok). Now I can do something in my app with my webservice:
ServiceReference1.WebServiceSoapClient obj = new ServiceReference1.WebServiceSoapClient();
await obj.MyVoidFunctionAsync();
Notice that ServiceReference1 is the namespace I assigned to the webservice when I added the reference in my app.
This actually runs MyVoidFunction(). However I cannot directly call the method obj.MyVoidFunction() and I cannot call non void functions and get their return values.
The questions
How should have I created the web service? Is asmx the right template for what I need to do? If not, can someone provide some documentation on how to do this, because everything I found refers to asmx and dates back to before 2010.
Is there any way to directly call the methods defined in my webservice without using await and the autogenerated FunctionNameAsync() method?
You are finding so old documentation because web services implementations are really old and there's no news on this.
If you are making a Windows 10 app, you should stick with newer technologies and it should be an JSON API.
Try to find documentation about how to create an API with WebApi, Azure has an product for that (http://azure.microsoft.com/en-us/services/api-management/).
In your Windows 10 app use HttpClient to consume this API with NewtonSoft.Json to serialize and deserialize your objects.
I've created a web service using Java (Netbeans IDE). The web service is a web service with MySQL database. and now I want to create a client application using C# Windows Form (Visual Studio IDE). I've added a web reference (wsdl link) on a client project. but I am confused about how to display the records from my database on my C# Windows Form.
Need help pleaseee,,, thx before...
You should add a service for get a value in your web service.for example GetData and in c# call the service.
Every service returns a specific type for example List<> or a class like Person.
Hello i have to develop an application in which im able to send some data(notification) from my webform to windows form and similarly from winform to webform.
Someone told me that i have to use web service for this purpose. so if someone please tell me how can i do that?
Im using C# for this purpose.
The general pattern from Web forms -> Win forms:
Add a WCF service to your Win forms application.
Implement the interface.
Use a ServiceHost and start the service somewhere in your initialization code.
Start your Win Forms project.
In your web forms project, Select References -> Add Service Reference.
Enter the URL in the Forms application's config file. (this is added when you create the service) the service should be discovered and proxy code generated automatically.
rebuild the Web forms project, you should have access to the Win forms service methods.
Services in the other direction are similar, but you don't need a ServiceHost implementation (IIS will host the service automatically)
You'll probably want further configuration as well. Possibly different bindings, and security.
I have a sharepoint web service running at specified host + "/_vti_bin/UserProfileWebService.asmx". I would like to instantiate a web service client, so that i could interact with this service. This is basically what I am trying to do: http://msdn.microsoft.com/en-us/library/ms550407.aspx.
How is this done in .NET? And do I have to use the MOSS API to know what functions it supports?
EDIT:
I guess I should add that I want to connect programmatically, not through a web reference, because that seems to be static.
In VS (2008/2010) you can add a web service reference to your console project for example. It will auto-generate the proxy classes for you to use in your code.
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.