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.
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();
Related
I am trying to connect to Magento API using C#. I am using Magento Go service and from what I've read I am able to use their API - I hope I am not wrong here. So here is what I did:
I added a Service Reference to http://mydomain.gostorego.com/api/v2_soap?wsdl=1, and just adding a service worked fine. Now I created a test class with GetStuff() method, which looks like this:
using ww.Feeds.MagnetoGoService;
public static string GetStuff()
{
MagnetoGoService.Mage_Api_Model_Server_V2_HandlerPortTypeClient s = new MagnetoGoService.Mage_Api_Model_Server_V2_HandlerPortTypeClient();
var login = s.login("username here", "key here");
return login.ToString();
}
When I run the program I get an error in first line saying:
Could not find default endpoint element that references contract 'MagnetoGoService.Mage_Api_Model_Server_V2_HandlerPortType' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Any ideas what this may be? Do I have to set something up in my Magento Go settings? Or maybe using Magento Go is not allowing API access?
Thanks a lot.
Forget SOAP with c# you will pull your hair out. Download Charls Cook's xml-rpc api libary for c# and use the xml-rpc method. You won't get all the snazzy intellisense but at least it will work. There's also c# solution from ez.newsletter they released with Cook's library demonstrating how to use 80% of the magento api calls.
Cook's library xml-rpc.net
http://www.xml-rpc.net/
ez.newsletter solution
http://code.google.com/p/csharlibformagexmlrpcapi/
If anyone ever has problems with this, my solution was this:
I used the reference in one project, but I actually called the class and had main program in another project. You need your Service reference to be in each project wherever you're using it. That fixed it! Alternatively you can create a new BasicHttpBinding() and putt all the options from app.config/web.config into that binder, then you don't need to reference to Service everywhere. I hope that helps!
I am trying to consume a SOAP service in C#, so I added my WSDL as a Service Reference. So far, I have created an instance of the request I want to send, but I don't know how to send it, or process the response.
Can someone explain how to do this?
When you added the service reference, Visual Studio should generate some code for you, including a class for the service which is in its own namespace.
So, you need to create a new instance of this service:
var oService = new ServiceNamespace.ServiceClient();
Then you can call your methods on the service:
oService.SomeMethod();
here you can find the full documentation and sample:
http://msdn.microsoft.com/en-us/library/aa529276.aspx
Here is a full example of How you create a WebService and How to consume it. As I see you just need the part of how to consume it. But it is like a normal call function you send parameters and receieve a result parsed to an object. Sometimes Value Objects created by the Service Reference Tool. Hope it helps.
By the way it uses the Web reference, with a service reference is quite similar just the name of your Class is parsed with a SoapClient at the End, lets say that your service is named Foo, the Service reference will generate it for you like FooSoapClient
I've been tasked with creating a class wrapper for a SOAP service, the idea is that you'll be able to treat it as a regular class. The main reason for this is that the WDSL for the SOAP service contains only one method and it's got 5 parameters and it's only kind of OO so you'd have to know all the method calls really well and it's a bit hard to remember them all.
OK, so I've tried adding a web reference, now web references can now be added as service references in VS 2010. You click add service reference advanced etc and it puts in a service reference. Great. Unfortunately if I try and access this from a class I can't.
I can build a console app and put code in the main procedure and access the method of the SOAP service fine but when I add a reference to a class library the intellisense won't allow me to select anything. I'd instantiate an instance like so:
SOAPService.webServiceService ws = new SOAPService.webserviceService();
ws.
and then the intellisense refuses to kick in. If I do the same in a web project or a console app then I can access it fine. I've added the namespace I've done all kinds of things. Also, I can add a web reference and get a DISCO file whenever I create a web project.
OK, also while I'm on the subject I also need to pass credentials to the web service in PHP.
The problem is that in the past I'd create some .net system credentials and add these and it would usually pass through if I was connecting to another .net service.
How should I be sending them to a PHP web service? I always get either invalid username/password combo errors or envelope malformatted error types
Thanks
Mr. B
So the intellisense is not working, but if you add the method in and try to use it does it work, or produce an error?
With regard to diagnosing authentication issues try using fiddler to view the SOAP messages that are being sent, and to view the reply. Do you have some other software that connects and authenticates to that service? Use fiddler to look at the SOAP messages and compare them to see if the header is different etc.
I'd normally do it like this,
using (Service service = new Service())
{
service.ClientCredentials.Windows.ClientCredential.Domain = "domain";
service.ClientCredentials.Windows.ClientCredential.Password = "password";
service.ClientCredentials.Windows.ClientCredential.UserName = "username";
}
Also with regard to the service working or not in general use fiddler if you have any problems, you can see the SOAP messages and it often gives you a clearer message.
I know in IIS you can turn on failed request handling that also gives you an insight from what is going on at the server end, perhaps you have some form of logging too for your php service?
This seems like it should be really simple, but I'm unable to figure this out.
I am adding a web service reference to my console application. The web service points against our production environment and I would like to test it against development. In VS2005 it was really easy to override the target URI of the service. Is it possible to do the same with VS2008? I would like to set the URI in code or via a config file.
I would really appreciate help with this. Thanks!
If you look in your .config, you should see <endpoint> elements that were added to the <client> section of <system.serviceModel>. Assuming you need to point at only one environment at a time you can simply edit the address attribute of those endpoints to point to whatever URL you want.
If you wanted to change this at runtime you need to use the constructor overload for the client proxy that was created. There should be several overloads that take a parameter called remoteAddress in many forms.
It seems that I was able to get around this issue by going to "Add Service Reference" -> "Advanced" -> "Add Web Reference". This gives me a reference in the form I am most familiar with. Now I was able to override the constructor with the URI parameter. Is that method frowned upon?
Scenario:
I am using Silverlight 3.0 as client for a web service.
Design:
The server has a class named DeviceInfoService which has the basic functionality of getting the list of devices, getting the properties of devices etc.
When I open an ASP.NET project and try to add a web reference, I can find an option to add a "Web Reference". After I add the web reference this way, I am able to access the DeviceInfoService class by creating it's object and then accessing it's methods.
Web Reference v/s Service Reference:
Coming to Silverlight: when I try to add a service reference, there is no option to add a web reference. Going with Service Reference, everything works fine till WSDL file is downloaded. People say that I can get this option by going back to .NET 2.0, but probably Silverlight won't work in .NET 2.0
The Problem
Now when I try to access the class DeviceInfoService , I am not able to find it. All I get is Interfaces -- DeviceInfoServiceSoap and DeviceInfoServiceSoapChannel. Classes named DeviceInfoServiceSoapClient.
The methods GetHostedDevices and GetDeviceInfo are no longer available. All I get is GetDeviceInfoRequest, GetDeviceInfoRequestBody, GetDeviceInfoResponse and GetDeviceInfoResponseBody.
I googled a lot how to use these four classes, only to find nothing. I want to get those 2 classes directly like in ASP.NET and not using those Request Response type.
You sound awfully confuse about some concepts.
How about you watch the following Silverlight.Net video and see if that helps?
How to Consume WCF and ASP.NET Web Services in Silverlight
What is web reference in ASP.NET is equivalent to service reference in Silverlight.
Here's an example of how to use a web service in Silverlight, e.g. the CDYNE Profanity Filter.
Add a new Service Reference to your project, URL is: http://ws.cdyne.com/ProfanityWS/Profanity.asmx?wsdl, leave the name as ServiceReference1.
Use this code behind to call the service (which was implemented to be asynchronous):
public MainPage()
{
InitializeComponent();
string badText = "I wonder if the filter will filter this out: shit bad luck";
ServiceReference1.ProfanitySoapClient client = new ServiceReference1.ProfanitySoapClient();
client.ProfanityFilterCompleted += new EventHandler<ServiceReference1.ProfanityFilterCompletedEventArgs>(client_ProfanityFilterCompleted);
client.ProfanityFilterAsync(badText, 0, false);
}
void client_ProfanityFilterCompleted(object sender, ServiceReference1.ProfanityFilterCompletedEventArgs e)
{
string cleanText = e.Result.CleanText; // Web service callback is here
}
And you've got a web service up and running in Silverlight!