Web API to insert records - c#

I am working on Taleo web API. I have an XML file with several records that I will have to insert into the Taleo system using its web API.
I have got the Taleo API guide from http://tbe.taleo.net/products/TBE_API_Guide.pdf.
For the first time, I am working on web API so I don't know where to start. Although the guide shows some examples using SOAP, I don't know how to make this request and retrieve the response using C# or VB.NET. I googled it but didn't get much information about it. If you share your ideas, I would really appreciate it.

From the PDF, it appears the WSDL for the service is at: http://tbe.taleo.net/wsdl/WebAPI.wsdl. In your C#/VB project, use the "Add Service Reference" option on the context menu and supply that URI to the WSDL. That will generate a proxy and many ancillary classes on which you can call whatever methods you need - the SOAP details are under the covers. You'll instantiate an instance of WebAPIClient and should see all the relevant methods there.
For example, in C# after creating a new Service Reference with (uninspired) namespace name of ServiceReference2, I can code the following (though I have no idea what it does!):
var x = new ServiceReference2.WebAPIClient(); // I suspect there's an overload expecting credentials
ServiceReference2.AccountBean y = x.getAccountById("bar", 0);
Exception handling is left to the reader :)

Related

How to create a SOAP Request C#

I know there are thousands of step-by-step samples for consuming a SOAP project with C#.
Actually, I tried many of those but didn't really get to understand how it works, how were needed components built or how to integrate a certificate for a secure connection.
I would be really grateful if any of you guys have a magical resource, since I read somewhere I shouldn't do it this way or another, I really want to know this well.
Thank you,
Best regards.
It's really simple actually. Suppose you have a service at http://myhost.com/XService.svc - right click References in the solution explorer and choose "Add a service reference" (older versions of VS called it web reference/web service)
A wizard appears; pop your URL into it, set a few options and hit Go
You'll get a client class set created that references the service, with methods that take a set of typed parameters based on what the service said it wanted when VS queried its WSDL. You might use it like:
var c = new XServiceClient();
bool result = c.CreateNewPerson("John Smith", 30, "js#hotmail.com");
The service client handles all of the xml creation, tcp socket connection, data transmission etc necessary to pass those 3 values you sent, to the web service so that the relevant method is called, the response is returned etc

C# Calling Web Services to different URLs

I'm new to Web Services from C#, but have worked C# for years, just never needed to use Web Services. Due to privacy issues, I can't disclose actual URL, but there is a test server and a production server where the web services are identical in all other respects, and the services were written / managed by another entity.
https://LiveSite.SomeDomain.com/FolderInWebSite/TestWebServiceSoapHTTP
and
https://TestSite.SomeDomain.com/FolderInWebSite/TestWebServiceSoapHTTP
Do I need to create two separate web references to the project and create different instances of them to go, or can I via some property just change which URL version it is sending data to.
Additionally, not being familiar working web services, I see the classes as Visual Studio imported. I can create instances of the classes and set the applicable properties (int, dates, strings, string[] arrays, etc). But not seeing how to actually say ... Go send it now. and then getting the response back.
I've done this from an older application with another language and was doing direct with HTTP and SOAP where I was able to make my own connection to the URL, build the body of the SOAP message, then send it.
Just use the "Url" property.
var myProxy = new MyProxy();
myProxy.Url = "http://foo.com/myservice";
Edit for second part of the question:
There should be a method for each action exposed the API that you can call. For example if the API exposes a MyAction that takes a string, the code generator should have generated a method that you can use like so:
myProxy.MyAction("hello");

c#: How to consume webservice methods whose address is unknown at compile-time

I am consuming a webservice from a Java server. The webservice provides me with some methods that need. Up till now I have been using the method where I added the reference of the webservice in the project explorer, typed the address of the webservice and compiled it. But now I need it to pick up the address of the service at runtime from an xml file or something! is that possible?
There is Url property in generated proxy object that you can set at runtime. Covered in Creating the Web Service Proxy article on MSDN.
Sample from the article (shows how to also set credentials, you may also need to set Proxy):
var rs = new ReportExecutionService();
rs.Url = "http://<Server Name>/reportserver/reportexecution2005.asmx?wsdl";
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
Note that above answer is for case when you don't know exact Url of server till runtime, but you have WSDL/sample server available at design time and able to generate proxy via add web service in VS (or manually).
Alternatively you can call service via other classes implementing "HTTP GET" like HttpClient and configure anything you want, but will need to do your own parsing of results.

C# Web Service client that will fail if WSDL is not available or invalid

My client hosts a few web services and has ASP.NET Web pages that will demo the web service and acts as a quick check to verify that the web service is up by the client. The problem is that the WSDL might be missing or invalid, but the Web Service will still work.
What I'd like to add to the ASP.NET web service client is a way to verify that the WSDL is there and valid, but have no idea where to start. Any suggestions would be greatly appreciated! Code behind is C#
I'm not entiery sure what you mean with verify that the WSDL is valid. Only thing I can suggest is, use an HttpWebRequest on the specific URI and see what response you get then either throw an exception based on specific status codes like 404 for example or handle it in a different way.
You can fetch the status code value
var request = (HttpWebRequest) WebRequest.Create("http://example.com/service.wsdl");
using (var r = (HttpWebResponse) request.GetResponse())
{
var result = r.StatusCode.ToString() == 200.ToString() ? "Success" : "Service not found";
Debug.WriteLine(result);
}
Hope this helps, goodluck.
Edit: if you know what services you're going to be testing you can simply add them as service reference in your client project and try to do an RPC on the service methods to see if it's available. Pictures below show to add a service reference.
Your scenario doesn't completely make sense. You could make a request to the service WSDL endpoint, http://something/service.asmx?wsdl and you could confirm that what comes back is a WSDL file. You could even validate it against the WSDL and XSD schemas.
This wouldn't tell you whether it was a WSDL that represented the service. It could conceivably be a WSDL for some totally different service.
Maybe more importantly, have you had problems where the service was available but the WSDL was not? In that case, rather than create diagnostics, I recommend that you fix the problem.

Web services to validate the canadian address through purolator webservice

Hey I am trying to use Purolator Web services to validate the address.
I already included web services in my project and have all credential to communicate but I don't know how to validate through web services and it's my first time that I am using web services please help
I am using C#
I have three input field to asp.net to validate
city
Postcode and
province
If someone can give me details info how to this validation through web service I will really appreciate their help.
Please give some sample code how can I do this
already included reference
using com.purolator.devwebservices;
com.purolator.devwebservices.ValidateCityPostalCodeZipRequestContainer;
This is how it show in their documentation.
I like to upload the picture to show you the web service request and response diagram but I don't have privileges
ValidateCityPostalCodeZipRequestContainer
ValidateCity PostalCodeZipRequest
tns:RequestContainer (extension)
tns:Addresses SenderA ddress - ShortAddress[]
tns:ArrayOfShortAddress
tns:ShortAddress
tns:ShortAddress
tns:City City -string
tns:Province Province - string
tns:Country C ountry - string
tns:PostalCode P ostalC ode; - string
In order to call the webservice, you first have to add a web reference, which you already did, now you need to instantiate the object of proxy class which from your post i believe is ValidateCityPostalCodeZipRequestContainer and call the RequestContainer method of object with required parameter to validate the address.
* Answer above is based on my assumptions becuase I don't have any information about the webservice. If you can post WSDL then I can give a precise answer.
Between, according to Purolator's website there are number of sample available here: https://eship.purolator.com/SITE/en/content/developmentprocess/websservicesprogram.aspx
May be you can find one using asp.net
And by the way there is a nice tutorial given here for consuming webservices in asp.net: Calling Web Service using ASP.NET.

Categories