For some reason I cannot instantiate the class nor access the namespace of WCF service references I add to my VS2010 project. I had this problem last week too and I solved it by creating a new client project, however I don't want to do that every other day when I need to add a service reference.
Does anyone have any experience with this kind of problem?
I found my solution at Sometimes adding a WCF Service Reference generates an empty reference.cs
I chose to configure the service reference and unchecked "Reuse types in referenced assemblies", that solved it!
Related
I have an existing WCF Service. I want to add it as a reference to a class library whose target framework is .net6, so that I can call WCF service methods I cannot see any option to add the service as a reference to the class library.
I am using Visual Studio 2022.
Is there any way to do this?
#madmonk46 comment helped me in adding the service as a reference.
So you need to right-click the project in Solution explorer, then click on Add then Service Reference.
Then you can follow the instructions which are mentioned here. you can ignore the first point.
I'm trying to access a WCF service in my MVC project. I added the shared service, i used this tutorial: http://www.c-sharpcorner.com/UploadFile/krishnasarala/accessing-wcf-service-in-Asp-Net-mvc-application/
Now i'm having issues making an instance of it. I called my reference "ServiceReference1".
ServiceReference1.ServiceAuthorClient obj = new ServiceReference1.ServiceAuthorClient();
But i keep getting the namespace could not be found.
What am i doing wrong?
couple of things to try
1 - do you have System.ServiceModel referenced in the MVC project.
2 - Go to your ServiceReference - press the show all files button at the top of the solution explorer - you should see Reference.cs under the service reference. Look in here for the namespace, and generally check it has the right auto generated code.
I have developed a WCF service that has been working fine for a few weeks now. I publish this service to IIS directly from the development server. I have a dev test app that includes this WCF service as a Service Reference in its own project.
My WCF class library also references another project within the Visual Studio solution, and many classes are in the referenced project that are used by the service and calling applications.
Today, after publishing some changes to the service (I did not make ANY changes to the referenced project or its classes), three of about 20 of the classes in the referenced project are no longer in the service reference of my test app. I cannot use them in code any longer, and they are no longer in the Reference.cs. I double checked, the classes in question are still decorated with [DataContract] and the properties are all still decorated with [DataMember] in the service solution.
Everything is building in Visual Studio OK.. I have rebuilt and republished everything, the missing classes are set to compile, I have tried IIS resets, completely deleted the IIS site and did a clean republish, no avail. I have tried deleting the service reference on the test app and getting a clean proxy every time as well. Nothing is working.
I then tried making a dummy class in the referenced project and built it in. Republished the service again, and even this dummy class does not appear in the Reference.cs. I am at a complete loss as to why these classes are not included in the .dll for the referenced project after it is published as it is evident that everything is building OK in Visual Studio.
I face such problem.
Following steps help you
1. Right click on Service ( In Service Reference Section of Project)
2. In Update Service Reference click on Advanced
3. Do as attached image.
Wanted to come back and post what was causing my problem:
I had made changes and none of my service methods used the 3 "missing" classes as a return type or parameter anymore. I simply had to un-comment the methods that used those classes to make them usable again. Makes sense now but I was convinced something else was wrong.
I faced similar issue and resolved it by doing the following.
Add the address of your end point with mexHttpsBinding.
E.g., Lets consider the address as mex.
While configuring service reference append /mex at the end of your service URL.
https://service.domain.com/serivce1.svc/mex
This will enable metadata exchange. So Reference.cs will be modified / added (if you are adding service reference for the first time).
Please Make sure that your service has an end point with mexHttpBinding / mexHttpsBinding
Edit : On analysis I found that this issue happens when the service is exposed via more than two end points (including mex end point)
I'm following this example for connecting to the Bing Maps geocode service:
Link
About half way down the page, it explains how to add a service reference in Visual Studio 2010, which I was able to do successfully. Then it says to add "using GeoCode.GeoCodeService", but when I do, I get an error saying "The type or namespace 'GeoCode' could not be found"
Am I doing something wrong. The steps are pretty simple and nothing gave an error. What else do I need to do in order to access the service?
After you added a Reference using your WSDL URL:
Under Solution, under Service References, right click on your Service Reference folder that you want to reference (example: com.gold.services.description1)
Select View in Object Browser.
You will see the class name in the Object Browser window that will open up.
(example: GoldWeb.com.gold.services.description1)
Copy and paste the class name into your code.
Example:
using GoldWeb.com.gold.services.description1;
Then you are ready to start using its classes.
When you added the service reference, you gave it a class name. Have a look in your solution explorer to see what you called it, and then you have to instantiate that class to use the service.
I seen this happen, when a service may be added to one project and is being back referenced in another project. For instance, the main project has the service reference, but library code, that's is reference in the main project, tries to instantiate the webservice. This is a circular/backreference and you can't add the namespace of the main project back into the library project, since the library project is already reference into the main project. I know this seem obvious, but in really big projects, it's easy to get lost to where you're at in code.
For brevity purposes, this post relates to ambiguous references in a Silverlight Page.XAML.CS file, whose project contains a service reference to a WCF service and a MyClass.cs file added as a 'link'. The Solution contains the Silverlight Project and a Web Project that contains a WCF service and a MyClass.cs file (along with the aspx files etc).
For some reason I am getting ambiguous reference errors once I add the service reference to Page.xaml.cs. Prior to adding the using statement for the service ref, I had one for MyClass.cs (which remember had been added to the SL project as a link) to the page, and it was running fine. Once the SVC ref is added, the compiler complains about ambiguity in my call to any class / property in 'MyClass.cs, such that a reference to MyClass.Class becomes ambiguous to 'ServiceReference.MyClass.Class...Seems very strange to me.
Assumptions & Clarifications
I ensured that no namespaces, class names, methods or variables had similar names
WCF service must reside in web application to have access to other non Silverlight assemblies etc
Other .cs files in the Silverlight project reference MyClass.cs, otherwise I would have simply removed the link to MyClass.cs, and allowed referenced MyClass.cs through the service ref.
My assumption here is that this has something to do with adding a file as a link? Any KungFu Masters out there able to offer some insight as to why this is occurring, alternatives to adding as a linked file, other ideas?
Is MyClass a class used by the service for which you added a Service Reference? If true, then there are two versions of each class in MyClass.cs: one from MyClass.cs, and one from the service reference.
You should pick one or the other - either use the service or don't use the service.
If you've added "MyClass.cs" as a link in both your Silverlight and Web projects then it will most likely cause a name collision, fortunately they should be in seperate namespaces. The linked class will be in the original namespace and the one generated by the Service Reference will be in the generated namespace.
You can use the "Reuse Types in Referenced Assemblies" option when generating the Service Reference so that the generated service proxy uses your linked class rather than generating a new one. There are however a couple of tricks to get this to work correctly, I outlined these in a post a few months ago Resuing types in Silverlight Service References.
I hope this helps.
Nigel Sampsons Answer led me in the right direction, thanks a million!
The Solution
Create a new project for the class file, and add a reference to that project in your Silverlight Project. Then when you ad your service reference and select "Reuse Types in Referenced Assemblies", it will not generate it's own implementation of the class, eliminating the ambiguous reference.
Unlike a typical client / server service scenario the class file must be compiled seperately for Siverlight and ASP.NET.
I've been able to overcome this issue by simply un-checking the re=checking
"Reuse types in referenced assemblies" when I configure the service reference. I was getting ambiguous references between the Class Library and the service reference which resulted in what I refer to as a cascade of errors, growing with every move I made.