How do I consume a ColdFusion webservice from C#? - c#

I'm trying to use a webservice with the endpoint https://services.example.com/ASP_SecureWebServices.cfc?wsdl.
In the documentation I have this:
Request
<authorise>
<site>xxx</site>
<login>xxx</login>
<password>xxx</password>
<partnerid>xxx</partnerid>
<wstype>xpt_exhibitors</wstype>
</authorise>
Authenticated Response
<authorisation>
<service>getAuthToken</service>
<authorised>OK</authorised>
<authtoken>255461</authtoken>
</authorisation>
I’ve never used ColdFusion before, so I don’t understand how to make the request. Can anyone assist?
I’ve added a service reference like this:
But I don’t get this method:

You're actually hitting the CFC directly, but you add ?wsdl on the end to actually have it return the WSDL.
Also, all of your methods in that CFC that you want accessible will need access="remote".
So your actual endpoint would be closer to this:
https://services.example.com/ASP_SecureWebServices.cfc?wsdl

Going to go out on a limb, but my guess from the documentation is that the method you need to access is called authorise. With that in mind, you would call the web service as follows:
https://services.example.com/ASP_SecureWebServices.cfc?method=authorise&site=xxx&login=xxx&password=xxx&partnerid=xxx&wstype=xpt_exhibitors
By default, ColdFusion will return a WDDX packet; if you want JSON instead, add &returnformat=json.

Check the WSDL to find out the methods exposed in the web service.

Related

Accept WCF request in WebAPI

I need to enable my webAPI REST service to accept a request in the format of:
www.someURL.com/OldService.svc
I am working on an existing application that used to use WCF. These methods do not have to return anything but a 200 response. We need the REST service to handle this call so we can retire the old WCF service, but systems will fail if we don't support this WCF request.
Has anybody done this before?
edit:
Is it possible to do this with just adding a new route?
You can add a WCF service (.svc) to a Web API project by simply adding a New Item and selecting Web, it will then show up in the list as WCF Service.
Maybe you could use the Route attribute(using System.Web.Http) for the old service? I've used this for route names like [Route("SomeRoute")] but I'm not 100% sure if the .svc extension will interfere with anything.
[Route("OldService.svc")]
[HttpPost]
public HttpResponseMessage NewData(Data SomeData)
{}

Methods Missing When Consuming a Web Service

My task includes consuming the Web Service Function which I got from WSDL.
After adding reference to WSDL in C# I am unable to find a service request method by simply calling the class.
Instead it has few other methods to use per service which I am unable to understand how to use them: ServiceNameRequest,
ServiceNameResponse, ServiceNameCompletedEventArgs...
Any idea how to utilize the WSDL in c# with this approach?
Assuming this is a service reference:
Look for ServiceNameClient class. The operations you are looking for will be off of that.
so say its the User service. There should be a UserClient. Off of UserClient you should have things like UserClient.Getuser or UserClient.Adduser etc.

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.

Test availablity of WCF URL

I am trying to test the availablity of WCF service as a part of a tool.
Is it possible or do I have to call a method inside that WCF to really test that?
I have tried client.downloadurl(wcfurl) but it is failing.
Any Ideas?
To test the existence of a WCF service all you need to do is enter the url of the service into a browser:
http://www.yourdomain.com/yourservice.svc
You should be able to make the same http request in code and check the response. If it's OK then the service exists.
This doesn't check the methods on the service though.
Create a HTTP request using the URL of your service. Don't forget to set the timeout. The response code 200 means it is all OK
I would try this tool from microsoft.
They provide you this, simply launch the tool and you will see the available methods as exposed on your IService.
http://msdn.microsoft.com/en-us/library/bb552364.aspx
You can provide the IService code for feedback.

Categories