What do I need to call a web service over https in C#?
Do I need to get the certificate form the site? How do I use this to call the web service?
There's nothing special or different for calling a web service over https than over http. You generate a client proxy from the WSDL using either svcutil.exe (or Add Service Reference in VS) or wsdl.exe and invoke the method. The lower level classes HttpWebRequest and HttpWebResponse will eventually take care of the actual call and certificates but it should be transparent for your code. Of course the server hosting the web service needs to provide a valid certificate.
I take that you are using Visual Studio to create your projects, if you are it is pretty easy to do. I take that you have the url for the web service that you would like to connect to and it starts with HTTPS.
In your project in the solution explorer (assuming you using Visual Studio), you should see a node saying "References" and another one saying "Web References". Right click on the "Web Reference" and then basically follow the wizard. It is pretty straight forward. You can spec your own Namespace. I usually use the format SomethingAPI. Then use the API as you would like any other object in your project. You will get the intellisense and all.
There might occur known problems with some certificates though. See http://support.microsoft.com/kb/823177/en-us
Do you have a client certificate that has been supplied by the provider of the web service?
If so, there are various different ways of doing this depending upon which version of .NET you are using. What version are you using, and are you limited in how you can generate your client proxy classes?
Related
I am trying to migrate my code from normal wpf application to Universal Windows Platform.
Previously I have used VS 2012 for Developing my WPF application And its working fine. Now I want to use the same application for mobile also.I found UWP as a solution for it. Now I am using vs 2015 . But here in vs 2015 I am unable to find Web Reference Option I am able to see only Service Reference. Actually My situation is I am Dynamically taking Ip Address and port number from User Based on the request I am connecting to that particular services like
public const string GET_SKU_DETAILS = "http://{0}:{1}/OmniRetailerServices/SkuServices/getSkuDetails?skuID={2}";
So like this I am connecting to particular Remote servers for accessing services.
And I did this using Web References in vs 2012. But Here in vs 2015 I am not able to find Web Reference. So My Question is How can I do this in UWP application Using VS 2015.
Please Help me to solve this Issue.
Thanks In Advance.
Web references (ASMX web service clients) are considered as legacy even in classic desktop applications, such as WPF. Service references (WCF service clients) are their successor and as you already noticed, they are available in UWP apps.
Just create a service reference instead of a web reference. You should be able to create it by pointing at the same WSDL as you did to create a web reference.
You can change the endpoint URL when creating an instance of the client proxy:
// use the base URL without the method name
var url = String.Format("http://{0}:{1}/OmniRetailerServices/SkuServices", hostname, port);
var client = new SkuServicesClient(new BasicHttpBinding(), new EndpointAddress(url));
To invoke the web method, call the corresponding method on the generated proxy:
var result = await client.GetSkuDetailsAsync(argument);
Not knowing the details about your service, I tried to come up with reasonable URL value and names in my code to match the info you have provided. It should be enough to get you going even if they won't be identical in your case.
Yes you can. Just proceed as if you gonna add a new service reference (Yes I now that you need to add a web reference) then on the bottom left of the "Add Service Reference" window, click on "Advanced" option. Then, again on the bottom, you see "Compatibility" and near the "Add Web Reference" button, now got it! :)
you can't do this. you need to find another way like HttpClient.
HttpClient is the easy way to consume web services.
https://blogs.windows.com/buildingapps/2015/11/23/demystifying-httpclient-apis-in-the-universal-windows-platform/
Using wsdl.exe /l:CS /serverInterface, I generated a C# interface from a WDSL document. I've implemented that interface on a WCF class. The resulting service runs locally:
http://localhost:51454/TapasSim.svc
This shows the default site. The problem appears when I append ?wsdl to the URL:
http://localhost:51454/TapasSim.svc?wsdl
Unlike what I expected, this link does not return a WDSL document! Instead, it points back to the exact web page you get without the ?wsdl. As a result, I cannot reference the web service. If I run svcutil.exe it gives this error:
If you were trying to generate a client, this could be because the
metadata documents did not contain any valid contracts or services or
because all contracts/services were discovered to exist in /reference
assemblies. Verify that you passed all the metadata documents to the
tool.
But I would expect that error to have the same cause as the lack of reply to ?wsdl.
What could cause a WCF .svc service not to generate WSDL?
As it turns out, the problem was mixing two technologies. wdsl.exe belongs to the older "Web References" that predate WCF. The newer tool svcutil.exe is meant for generating WCF "Service Reference" interfaces.
So what happened was that WCF looked for [ServiceContract] and [OperationContract] attributes. When it couldn't find any, it silently did nothing.
The silent suppression of this condition is annoying, to say the least. An error like No service with [ServiceContract] attribute found would really have helped.
Note that you can manually add [ServiceContract], but that will leave you with half "Service Reference" half "Web Reference". The result probably will not work.
I had a problem with getting the WSDL via the IE window provided by starting the debugging session. I had to use a separate window, ensuring I put the HTTPS in the URL.
We are hosting our services on 443 (SSL). When you start up the debugger, even though the IE windows shows http: (80), it was listening for traffic on 443. FYI, this is controlled via the project level setting SSL Enabled
I have classes that are needed in both my web service and my server.
For example, I have a class named Order that I'd like to send from my server to the web service and vice-versa.
Problem is that the class in the server is Order and the one on the web service is localhost.Order, and it is impossible to convert between them, even though they are built from the very same code. Error is cannot convert from 'Order[]' to 'localhost.Order[]'.
What can I do? Thank you very much.
when you add reference to web service you can specify which classes to reuse. by default it generates classes based on WDSL that web service produce.
The namespace used is determined by the name you give the reference when you add it.
For more information see this answer to a similar question:
Unable to cast object of type MyObject to type MyObject
You should maybe have a look at WCF services:
http://msdn.microsoft.com/en-us/library/bb332338.aspx
I've used these on a few projects where both have references to a shared library, and one web site will request one of these objects via a WCF service call from another site. It's very clean, and it opens up other options for transport/security which can be very useful.
The question appears to suggest that you are using ASMX Web Services. If so, you have your work cut out for you.
Jelle Druyts wrote an extension for ASMX that can do, more or less, what you're asking. You have to configure your shared types at the machine level (machine.config). It's not pretty.
There's also a fix for that extension to make it work with nullable types.
Good luck getting this to work with Visual Studio 2008 or on Vista/Windows 7. You'll be OK if you're still running XP with VS 2005.
If you can, you really should consider using WCF for the client proxy instead, since WCF makes it very easy to share types. In fact, the Visual Studio 2008 integration does this by default; you just need to make sure your client project references the assembly containing the service types.
In a fairly standard fashion, I created a Web Reference to a SOAP service in Jira for an extension that I'm building (Jira is an issue tracker for those unfamiliar with it). Visual Studio auto-generates a .Settings file and an app.config that contains the web service URL.
Since I'm developing an extension/plugin to an ALM product we're building, the consumer of the extension will be the one who ultimately decides where this web service points to, because it will be integrated with the consumer's instance of Jira. Assume that the web service URL would be stored and pulled from a database.
How can I get the auto-generated service to use a URL from a database instead of from the generated app.config?
Note: we are using v2.0 of the framework, so WCF is not an option.
Even in the 2.0 web service you should be able to change the "Url" property of your web service proxy to the value you desire.
Use the constructor of the client that admits the uri.
i am new to c# language.i saw that you wrote the c# client application to the axis2 web service.i also want to know how i write C# client for the axis2 application
I believe that Axis exposes WSDL in the normal way, so you should be able to use "Add Web Reference" from Visual Studio, point it at the relevant Axis WSDL URL, and use the autogenerated client proxy.
I seem to remember there are some subtleties around using null vs empty arrays, but mostly it works fine - or did when I last tried several years ago, anyway.
For any new web service development, I suggest you use WCF instead of the old-style ASMX web services framework that you would get from using "Add Web Reference". Use "Add Service Reference" instead. ASMX is next to obsolete, in the sense that only critical security fixes are expected.
Many AXIS2 services are configured with WS-Security enabled, and WCF is the only practical way to handle those.