WCF RESTful: Adding a service reference in Visual Studio 2010 - visual-studio

I'm trying to add a service reference to a RESTful WCF service in Visual Studio 2010.
Actually, Visual Studio 2010 doesn't discover any service in my solution.
My question is: is this possible using RESTful WCF services?

Are you using the online WCF RESTful Service template to create your RESTful WCF service? This template uses a .cs file instead of a .svc + .svc.cs file. Which seems to make the "Discover Services In Solution" break (Does work against .svc + .asmx services however). A possible work around would be to implement it in the form of .svc + .svc.cs.
I've just tested this locally by creating a service using the RESTful template, adding a "WCF Service" using the add new file menu and moving the code from "Service1.cs" in there, and modifying the route table in Global.asax.cs to
RouteTable.Routes.Add(new ServiceRoute("TestService", new WebServiceHostFactory(), typeof(TestService)));

Related

checking validity for standard SOAP web service

Is this a valid web service link since I tried ti import it several times to visual studio 2010 and 2012 and couldnt read it from code behind.
http://www.hotelston.com/ws/HotelService?wsdl
whats the service name I should call ?
Yes this is a valid WSDL and it is a WSI compliant WSDL as well. I ran the tests with SOAP UI and it appears to be fine. The service name is HotelService it has three ports one for SOAP 1.1 another for SOAP 1.2 and finally one for HTTP. It is document literal wrapped so cant see anything problematic.
I also imported the WSDL into a XML editor and had a look. It appears fine see image below.

Is there a simple approach to call REST APIs from MVC3 applications

Can you recommend a library/simple approach to calling REST API services from ASP.NET MVC3. In Nuget I see things like RESTSharp, Hammock, Craig's Utility Library. I am looking for a common helper that I can then plug in multiple services.
Many thanks.
Starting a new MVC4 project comes with some default Microsoft WebApi packages for publishing and communicating with REST Apis - so if you have the opportunity to do this in MVC4 I would take it.
If not, you can still bring in the necessary nuget package into an MVC3 project to consume an api.
Install-Package Microsoft.Net.Http
The you can do things in your controller/domain layer like:
var client = new HttpClient();
var uri = "http://www.myapi.com";
var content = client.GetAsync(uri).Result.Content;

Dynamically set URL of web service

Scenario: I'm running code on the client that connects to a server and uses a web service to retrieve data about a SharePoint list. I'm using the Visual Studio 2010 "service reference" to get a web service for my SP Site and get my data from the list. It works. Now how do I go about coding it such that when I want to move from Test to Production, my web service calls will still work? Note that the web service is a SharePoint web service, I did not write it. I am only using it. Is what I am suggesting possible? I do have the ability to ensure that the Site is the exact same (except for URLS) on both environments (e.g. backup the SP site and put it on production). Thanks for any suggestions.
Summary:
Basically I'm looking for the best way to go from test to production without re-compiling my code which consumes the SP web service. Also, as a side note, if anyone knows how similar the test/production sharepoint sites have to be, [in order for the web service to work on both without anything but the URL being changed].. that would be helpful info.
Solution
The project configuration file can be used to specify the web service location. The .svcdatamap and other files in the VS project are for design time use only, and the URL which is actually used to connect to the SharePoint web service is passed as an argument to the System.Data.Services.Client.DataServiceContext object. This is only tangentially related, but to create your own WCF web service see this link. BTW, the web service will work without recompilation anywhere the SharePoint List has the same List name and the column you're querying has the same name.
As far as I know, Visual Studio Tools for Office projects allow you to have an app.config file in your project. I'd expect that Visual Studio created the app.config file and added the necessary configuration settings related to the web service reference. In any case, you need to store the correct web service url somewhere - app.config, registry or even a database.
If you are not able to store the web service endpoint address information in the app.config file, there's a way to configure the proxy manually.
If it's a .asmx reference added as a legacy "Web Reference" in Visual Studio then all you need to do is set the Url property value of the proxy object before you call any web service methods. For example:
MyASMXWebService proxy = new MyASMXWebService();
proxy.Url = "web service url";
proxy.HelloWorld();
If it's a .svc WCF service reference then things get a bit more complicated. You'll need to create your web service endpoint programmatically. For example:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress endpoint = new EndpointAddress("web service url");
ChannelFactory<IMyWCFWebService> factory = new ChannelFactory<IMyWCFWebService>(binding, endpoint);
IMyWCFWebService proxy = factory.CreateChannel();
proxy.DoWork();
Since SharePoint services (SVC) do not provide a proxy, option 2 will not work. References to both locations must be included in your application and then use a parm to differentiate production from test. I believe 2013 will likely correct this bug.
You have to edit the URL in your project's web.config
Simple SharePoint example:
MyService.ListsSoapClient client = new MyService.ListsSoapClient();
client.Endpoint.Address = "site url"+"/_vti_bin/lists.asmx";

How do I call a Web Service in VB6?

I have an old VB 6 Application. I now want to access a Web service/web method in it, I am using MSSOAPLib30 DLL for the interaction.
Everything is fine with the simple types like int string.
But I am unable to send Complex types like Class and Structs.
Anybody have any suggestions?
You need to create a Type Mapper.
Microsoft SOAP Toolkit Type Mappers
If you have the opportunity, you can make things much easier by creating the code to call the web service in VB.NET and then using interop to invoke it from VB 6.0.
Calling Web Services from Visual Basic 6, the Easy Way

How can I get started using a WSDL file with Visual Studio it's in the root of the project instead of being hosted on the internet somewhere

I've been tasked when integrating a web form into Oracle CRM on Demand (Siebel) using web services. I've been given the WSDL, and some high level documentation from Oracle.
Well, I knew I was in trouble when I tried to add the WSDL as Web Reference and I was asked to enter an URL. I have the WSDL file in the root of the project, but I have no idea how to link to it.
So, I guess that means I need to learn up on web services using C# and Visual Studio. I have a Safari Books Online account, so I can look up most anything.
It's been a while, but I'm OK at the form part. I just need help connecting and using the web service.
Edit #1: Ok, to clarify my question: I am well aware on how to use web services in general. My specific question is how take this WSDL file and do something with it. If the WSDL was hosted somewhere else, I could just add it as a Web Reference. But, I have the file in the project itself and that is what I am having problems with.
The web reference asks for a URL but you can point it to a local file. Just paste the local file path of your WSDL in and it should work.
Further Clarification of Web Reference URL vs URL to access Web Service
Web Reference URL is used to generate and update wrapper classes for WSDL/Web Service. It is not the URL used at runtime to access Web Service.
URL property on generated wrapper classes is used to access actual web service at runtime.
Update:
It should add a path in the web.config or app.config/settings file (Depending on your project type) similiar to the following:
<setting name="Namespace_WebReferenceName" serializeAs="String">
<value>XXX</value>
</setting>
Which should map to a URL property in the generated web reference wrapper classes. You can modify the URL property programmatically to point wherever you want:
Dim shipService As ShipService = New ShipService() 'Initialize the service - where ShipService is the Generated WebReference Wrapper CLass
shipService.Url = ConfigurationSettings.AppSettings("FedExOnlineURL")

Resources