I am wondering how to get to the Sitecore content through the Sitecore API in a separate webservice, I tried SiteContextSwitcher but I get a "Cannot load provider" Exception.
Should I somehow register this webservice in sitecore to use it ?
EDIT:
I would like to expose over WebService functions to publish specific items (by GUID or path)
You can use Sitecore Web APi module to get Sitecore Content .
Here you can find it.
I think you don't need your own WebService, with this module you can get Sitecore content out of the box. It's really easy to use it.
You can add web service to your website where you will have access to the Sitecore API and expose functions you need eg. publishing a page
You will need an ASMX service which you can call by URL to the file ie. http://server.com/Some/Directory/Service.asmx/YourMethodName
Since it's called in the context of the Sitecore application you will have access to the API in the service. You can pass the path to the item or the id using parameters.
Related
I'm trying to setup a ServiceStack template loosely based on the existing ASP.NET with razor template. The services to be created using this will be hosted in a variety of locations. What I would like is for them to be able to register themselves with a central server.
What I was hoping to do was to add some code to Application_start (or apphost) which would perform the registration however I can't find any way of getting the root url of the application. The normal method of using the request object doesn't work as there isn't a request object at that point.
If I can't get this from asp.net I'm wondering if there is a servicestack call I can make which can give me what I need
The URL for where an ASP.NET Web Application is hosted at is only available at runtime, inferred from the incoming are Request URL, so you won't be able retrieve it at Startup.
I am wondering - in my ASP.NET 4.0 website how to connect to the web service I have running?
This is essentially what I would like to accomplish, for testing before I apply it on a larger scale. I want the website to be able to send a value (int) from the website to the getData() method in the web service (auto generated method) and return its result (string) back to the website.
This is my setup for the Website/IIS 7/WCF:
Steps for creating website and service via VS 2010 (.NET 4.0)
Website:
File > New Website
I did not change anything on the default website template
Build > Publish Web Site
Set target location to specific folder
Other settings unchanged
IIS Settings:
Connections - Right Click > Add Web Site
Specified a site name
Specified physical path
Connect As: Set the username/password
Binding Default (http port 80)
Connections - Right Click on Default Web Site > Manage Web Site > Stop
...So as not to end up with two websites on conflicting port
Edit Permissions > Add user "Everyone"
MyNewSite > Manage Website > Start
...Clicked Browse Web Site > Brows *.80 (http)
And the website ran just fine, I was able to access it locally and through vpn with the IP address.
WCFService:
File > New Project > WCF Service Application
...I did not change any of the default settings in the WCF service
I ran WCF service as Admin, and it loaded the little test app where you can type in a value to the getData() method and it returns "You typed {some_number}".
So as far as I know - everything is working with the website and the wcf service. I tried also right clicking on the website in VS, and Add Service Reference and it was able to detect the WCF service.... however, I dont know that I should need to add a reference but simply connect to the WCF like I do to a database via a connection string of sorts.
To elaborate upon my comment, here's a stripped down example. You can find numerous examples of how to do this with a very simple Google search, by the way.
In order for your web site to call any of the methods, it must have a WCF client proxy. This proxy is used to establish the connection to the service and make calls to the methods the service exposes via the [OperationContract] attribute.
Taking your posted example above, if you created a basic no frills don't touch anything WCF Service Application, and you add a reference to it in your website from within Visual Studio, the WCF client proxy will be generated for you, as well as any necessary configuration file settings (in your Web.config file).
Once you've added the reference, you can then do something like the following in your website:
ServiceClient client = new ServiceClient();
string serviceResponse = client.GetData(5);
client.Close();
This would return "You entered: 5" for serviceResponse.
Alternatively, you could use the svcutil.exe to generate a *.cs file and and a config file. You would add the *.cs file to your website project and the <system.serviceModel> section of the config file to your Web.config, and then could use the above code to call the service.
A third way, and this is the way I prefer because of the nature of our application at work and it gives me more control, is to use ChannelFactory<T>, but I would suggest trying the above two approaches to get familiar with the basics first.
Again, see Accessing Services Using a WCF Client, and if that isn't sufficient do a Google search for more examples.
The key point here is that the client requires a proxy to communicate with the WCF service. How you generate that proxy is up to you and the requirements of your project.
I've got a WCF (RESTful) web service within an ASP.NET website project. The service resides at /WebServices/Registration.svc. I'm trying to create a custom BasicAuthenticationModule httpModule to handle Basic Auth as explained at https://stackoverflow.com/a/4729555/291323, but the module is being used for my entire website, which I do not want.
I tried using the tag to define the module for ONLY the service, but couldn't get it to work. I tried setting the path to both "WebServices/Registration.svc" as well as just "WebServices".
Is there a better way to register an httpModule to affect ONLY a WCF webservice within a website project?
TIA for any assistance!
I have a solution with a number of projects in..
One of these projects is a web application, another is a web service.
The web app references the web service, and uses the methods in there.
In production, the web application will be hosted on one server, while the xml web service will be on another.
My question is, how do i deploy this?
I've "published" the application to the correct server, however what do i do with the xml web service? and how can i configure my web application to point to the other server, rather than try and use localhost....
You generally won't leave your web service proxy classes with their default URL in production code. You can configure the production web service url in your web.config class and then have something like
MyWebService svc = new MyWebService();
svc.Url = WebConfigurationManager.AppSettings["MyWebService"];
Something along those lines should get you what you need.
When you add the proxy to you web application, you can set it to be dynamic url. This will create a config file entry that can be set during your deployment. Click on the Web Reference in the Solution Explorer, change the URL Behavior from Static to Dynamic from properties. An app.config file will be created with a key.
When I added service -> web service. The VS2008 added a App_WebReferences folder without a .asmx file. I see a .discomap file.
When I use the cascading drop down ajax control, it is looking for .asmx in the service path. Am I doing it wrong? I remember the early edition of Visual Studio added a .asmx file when you added a outside webservice reference.
EDIT:
I don't think I'm clear on my question. I have a ASP.net Webservice application that is setup on localhost/service. I want to reference to that service in my asp.net website. I first added the project to the service in the soultion add existing project then on my website i added the web reference via localhost/service. It now have a folder App_WebReferences and the service folder along with service.discomap, service.disco and service.wsdl
when i try to use the cascading drop down extension. the service path is looking for .asmx file so how do i setup the service path for the ajax extension?
If the dropdown needs to call the web service, just give it the URL of the web service (ex: http://localhost/mywebservice/service1.asmx). I believe you'll also need to give it the name of the web method to call.
You won't need to add a web reference to your project unless you plan to call the web service manually.
You added a reference to an external service. You'll want to create a new web service by right clicking on your project, then Add New Item and selecting Web Service.
Also note that if you make a folder, say, WebServices, and add the asmx there, it'll place the .cs file in App_Code. If you have a web application project, I'm not sure where it would put it since there is no App_Code.