joeb
joeb

Reputation: 877

Connecting to website's SOAP API with C#

I'm trying to connect to the a provider website which has a soap based API. I'm new to C# so I am not really sure how to do it. I've been googling around like mad but I am getting nothing but errors. Here is what I've done.

I've added the URL (ex:http://www.companysite.com/api/api.cfc?wsdl) as a web service inside my .net solution and gave it a namespace of CompanyAPI.

If i right click on the service reference inside the solution explorer window, then go to object explorer. I can see all of the available methods.

When i try to instantiate it is when I get errors like cannot instantiate an instance of abstract class.

'CompanyApi.Api MBApi = new MyApp.CompanyApi.Api();'

I have no clue what i am doing wrong. Thanks in advance for any help.

Upvotes: 2

Views: 2246

Answers (1)

luksan
luksan

Reputation: 7757

When you add a Service Reference in Visual Studio, it creates an interface to represent the service contract and a client class which implements the interface. You are probably attempting to create an instance of the interface directly, which is not allowed; you should create an instance of the client. The client should be named something like ApiClient, in which case you can do the following:

CompanyApi.ApiClient MBApi = new MyApp.CompanyApi.ApiClient();

Upvotes: 2

Related Questions