I have an asp.net Website that has access to database and has functions which I want to allow 3rd party users to use.
Is it possible to add WCF project/ WCF service to my solution so i could let 3rd party member having access to my methods?
We tried myWebsite->Add New Item-> Wcf service/wcf data service but that doesn't seem to work.
Any help would be great.
It's not working because you are trying to add a reference to an existing service for consuming it. You want the exact opposite.
For this, you will have to create a separete project of type WCF Service in your solution.
More info on creating WCF Services can be found on MSDN.
Keep in mind that if you want to expose certain features through the service, you will have to factor the functionally out of the website to another project that both the WCF Service and the website can consume.
You should be able to add a new WCF service project from the solution root in Solution Explorer...
Right-Click >> Add >> New Project
It's not clear from your question what 'doesn't work' though.
Your newly added project will need to reference the existing project that contains the methods that you want to access. You should perhaps consider if your current design is appropriate - ensure that you have separated out your presentation code (this should be your website project) from the common business functions that you want to share (I would have this as a separate class library project in the solution). Your WCF project can then reference the common 'business logic' project.
To reference your 'business logic' project from the WCF project...
Right-Click (on WCF project) >> Add Reference
Not sure what "doesn't work", but MSDN providers a walkthrough for adding a WCF service to a website here:
How to: Host a WCF Service in IIS
This has the step-by-step of creating a WCF (both markup and code) and adding the relevant web.config entries by hand rather than using the "Add Service" dialog.
If you create a separate project in your solution to run your services, you will need to reference your existing website project using the Add Reference option on the new service project. This will allow you to use the classes and functions defined in the existing project inside your new service project.
Related
I have deployed a WCF service to my cloud service web role and successfully tested it with my WCF Test Client. I can reference it as a service reference and it shows up the way i think it suppose to but I cant use it. Any ideas of how to work through this issue? I have tried to update the service reference, remove it and add it again.
(And yes, I have searched for a solution and read more than 30 results but nothing that actually has this problem).
The setup is a .net 4.5 cloud service web role with a WCF project template. Calling GetBooks method returns a string of Book objects. Then there is a WebAppConsumer web application based on the MVC .NET 4.5 Template.
If don't need to reuse types between the service and client, go to "Configure/Add Service Reference" Dialog, click the "Advanced" button and uncheck "Reuse types in referenced assemblies".
If you need to reuse types between the service and client, check the "Reuse types in referenced assemblies", choose the "Reuse types in specified referenced assemblies" and choose only assemblies that contain the types that you want to reuse, if it doesn't solve the problem, take a look at the "Error list" tab, it will contain more info that will lead to the type/s that cause SvcUtil to fail.
I am having an existing website which contains two directories a website and a class library file.
now am trying to add new web application to this,when I added it creates a web config for it.
How can i reference my new web application to refer from my website
For your reference,If I am doing something wrong please guide.
Thanks
Askar
You cannot reference a web application to a website.
If it is needed that you cn make calls via Service reference or ajax calls.
But you might have an issue with CORS than.
the question is why are you trying to put in one solution a web application AND a web service.
I think you should have one web application from which you create all the controls you need and refer the needed class libraries
I have one WCF service with multiple endpoints. Each endpoint has it's own configuration.
My problem is that I'm trying to figure out what will be the best.
1 - Add to my MVC application a service reference to each of the endpoints
2 - Create new DLL that will have the references to each of the endpoints and then add in my MVC application a reference only to this DLL.
I could really use your help to figure if there are any downsides to each of the approaches?
UPDATE
i forgot to mention that i have multiple MVC applications and each one uses only one or two of the WCF services.
to be more accurate, i now have 6 MVC applications and 7 WCF services. each MVC application uses only 2 WCF.
in the future the number of MVC apps and WCF will grow.
I would not use a server reference but just point svcutil to all three at the same time. It will generate one set of proxies and one configuration. It also allows you to share data contracts between the services.
Personally, I always put my web references and service references in a standalone assembly called SharedServices. That way; multiple assemblies can share the same references and datatypes can be shared among assemblies. Attaching a web reference to an assembly could lead to many projects being dependent on that assembly solely for the web service defintions.
You can write a service agent that is responsible for accessing the services, abstracting away this logic for your MVC application. The service agent would also be the place to implement other logic like caching, if you would ever need it. See http://tinyurl.com/cbcepgl, below under 'service agent' for some demo code.
My team and I have a asp.net web forms application and are using several class libraries. In one of those libraries, we are trying to consume a web service. The web reference was added in the web app project and the appropriate references have been added. The app compiles. When attempting to consume said web service in the class library, the credentials don't seem to work, and the call fails. However, if we take the web service call out of the class library, and consume it within the web app, it works.
Any ideas why this is not working in the class library.
Double check your configuration file includes the correct information for the Web service.
Try changing the URL behavior to dynamic as well.
Also, as John stated, I'm assuming you're adding the service to the class library because you intend to use it from the library, as opposed to other areas of the Web application.
"the credentials don't seem to work, and the call fails"...can you give a small stack trace of the error?
Just to clarify, in my current project, we use WCF endpoints within a class library with bindings and credentials. The same can be done for a SOAP ASMX Web reference as you're attempting.
You can add a web service reference by doing the following steps:
right click on the project on the Solution Explorer
click Add Service Reference
click Advanced
you will find "Add Web Reference" at the end of the form
If you are adding the reference in application and then consuming it from class library... How you call the class library.. by adding reference and invoking the method of class library and then how you are accessing proxy from the class library you need to reference it... It seems to me a circular reference. Which shouldn't be compiled at first place... Are you describing your structure correctly???
It's always better to add a simple project with just web reference and then add the reference of this project on all the projects which requires it.
You can add a web service reference by doing the following steps:
right click on the project on the Solution Explorer
click Add Service Reference
click Advanced
you will find "Add Web Reference" at the end of the form
By #AMgdy 's solution,It'll auto generate a Reference.cs class.It defined all of method of webservices.
May be you called it wrong!!
Here is an example:
var serviceName = new ServiceName
{
Credentials = new NetworkCredential("Username", "Password", "Domain"),
Url = "Here you put the correct url of the web service if you published somewhere else"
};
serviceName.CallWebMethod();
make sure that you entered the correct Credential username and password and make sure the you published the webservice to a place you access it.
Have you defined any credential information in a config file in the web app? If so, the class library probably can't fetch them correctly. Just a guess though. And John Saunders is right. Seems a bit backwards reading your description of your apps structure.
I just hit a huge brick wall with Paypal. I had created a regular C# project to create some wrapper classes using their WSDL.
If you create a non-web project, the only option you get to add a wsdl is a Web Service Reference. And this builds kinda the same set of proxy classes as a Web Reference would but not really..it adds more that even the PayPal guys are not aware of.
So I was this entire time looking for the right Interface in this list of proxy classes to use as the service (SoapBinding) and the PayPalAPIAASoapBinding was not there I kept telling our PayPal point in contact.
I could only see the following 2 Interfaces that appeared to me what I needed to use since I did not see a PayPalAPIAASoapBinding which you CAN see in a Web Reference based service reference:
PayPalAPIAAInterfaceClient
PayPalAPIInterfaceClient
So I figured out oh, I probably had created a Service Reference vs. a Web Reference which Web Reference is an option in a Web project. But I don't want my service reference tightly coupled to my web project. So that's why I created the C# Project.
So what the heck is a Service Reference vs. Web Reference? And how am I supposed to separate this out into anther project if Service Reference is going to throw me a loop and give me a set of different interfaces than a Web Reference would?
Also, to make things even MORE confusing, VS 2008 has a Web Service Application project.
So what do I use? We're using the .NET 3.5 framework and we're not ready to move to WCF. So can I still use the new Service Reference even if not using WCF or what? IF you're using .NET 3.5 and not WCF yet and you still want to do basic web services, do you still go the Service Reference route and just not use the WCF framework? Meaning can it be used like a .NET 2.0 Web Reference still, just that you're going to get an entirely different generation of the WSDL?
Add Web Reference is the old-style, deprecated ASP.NET webservices (ASMX) technology (using only the XmlSerializer for your stuff) - if you do this, you get an ASMX client for an ASMX web service. You can do this in just about any project (Web App, Web Site, Console App, Winforms - you name it).
Add Service Reference is the new way of doing it, adding a WCF service reference, which gives you a much more advanced, much more flexible service model than just plain old ASMX stuff.
Since you're not ready to move to WCF, you can also still add the old-style web reference, if you really must: when you do a "Add Service Reference", on the dialog that comes up, click on the [Advanced] button in the button left corner:
and on the next dialog that comes up, pick the [Add Web Reference] button at the bottom.
If I understand your question right:
To add a .net 2.0 Web Service Reference instead of a WCF Service Reference, right-click on your project and click 'Add Service Reference.'
Then click "Advanced.." at the bottom left of the dialog.
Then click "Add Web Reference.." on the bottom left of the next dialog.
Now you can add a regular SOAP web reference like you are looking for.
Adding a service reference allows you to create a WCF client, which can be used to talk to a regular web service provided you use the appropriate binding. Adding a web reference will allow you to create only a web service (i.e., SOAP) reference.
If you are absolutely certain you are not ready for WCF (really don't know why) then you should create a regular web service reference.
In the end, both do the same thing. There are some differences in code: Web Services doesn't add a Root namespace of project, but Service Reference adds service classes to the namespace of the project. The ServiceSoapClient class gets a different naming, which is not important. In working with TFS I'd rather use Service Reference because it works better with source control. Both work with SOAP protocols.
I find it better to use the Service Reference because it is new and will thus be better maintained.