Manually setting the namespace for a Service Reference - c#

When a Web Reference is added in Visual Studio the generated proxy class automatically uses a default namespace which consists of the application’s default namespace together with the web reference name. the problem is i have a profile web service which all my projects use that in order to authenticate. Because of the namespace i cant add a profile class as a link. Now I wonder if there is any way to manually set the Reference name? (or maybe there is a better way which could solve my problem.)
So far I've found this:
1- Go to the service Reference.cs and then rename the namespace.(the problem is every time i update the service the namespace goes back to the default)
2- I found this :Manually setting the namespace for a web service proxy class in Visual Studio(the problem is i have to change the build event which it could cause the unexpected errors.)

Use "Custom Tool" option with wsdl.exe and give the required parameters. Whenever you want to update the service reference run the custom tool by using below mentioned option.
/n[amespace]:namespace
For more information visit
https://msdn.microsoft.com/en-us/library/7h3ystb6%28VS.80%29.aspx

Related

Copy service reference from one project to another project in same solution

We have one service reference in one project of a solution. I am trying to move this service reference to new project in same solution. But adding the service reference in new project using URL present in the service reference of old project is throwing 404 error. I am not sure where is this service hence do not have it my IIS.
I tried to copy all the files and adding them to source control. like copy paste but then it has some auto generated code under reference.cs which generates all classes. They have old namespaces and might have to change it to new namespace manually. So, not sure if this can cause some other issue as I will be manually updating the auto generated code.
Is there a way to add this service reference in my new project?
option 1 - find the url by debugging the first project
Assuming that the first project accesses the WCF service correctly, you can debug it to the point where it makes the service call and look at the the remote address in the watch
var url = currentProxy.Endpoint.Address.Uri;
option 2 - add reference to the project thats already working
add a wrapper class that makes the WCF call in your original project and then add project reference of your original project to the new project. now you can you use the newly created wrapper to access the WCF service from the new project via the wrapper

Type or namespace name 'xxx' could not be found in Umbraco

When I created a class, there is no existing namespace declaration and I need the namespace declaration to access the class from a view (cshtml).
Normally when you create a class, there should be a namespace declaration included right? But for me I don't see any.
I already tried to add a namespace declaration, but I still can't access it from another class.
I hope you could help me with this.
Screenshots: https://drive.google.com/open?id=0B5TGcf9mTeg2V2ZDaldWelp6WXc
ScreenShot
make sure your namespace name is correct .using PRL(Capitalized) .Models .And the good practice is add an empty web application project ,not a website.
Just as what Nico Said (https://stackoverflow.com/users/5685258/nico)
Follow this instructions and this will be resolved:
https://our.umbraco.org/documentation/Getting-Started/Setup/Install/install-umbraco-with-nuget
Although I started all over again.
~I created a new project from Visual Studio 2017 using ASP.NET Web Application
~Selected an empty file
~ Right click on the project
~ Click Manage NuGet Packages and installed Umbraco CMS
~ Run it from VS and install the umbraco platform using the browser
~ As soon as I create a class, a namespace declaration will also be included.
Thanks!
Your model belongs to namespace PRL.Models but you try using Prl.Models - namespaces are case-sensitive. Try using PRL.Models
Edit: and for the class without namespace-declaration: you should always have a class in a namespace. Declare one.

.Net Generate Service Reference with Service Having type "System"

I'm trying to add an external service reference in a C# .Net 4.0 project where the service wsdl contains a type called "System", which results in something like this:
As you can see, everywhere in Reference.cs where the "System" namespace is referenced, it instead believes it to be this System class instead, resulting in errors all over the place.
What would be the best way of resolving this naming issue?
You can rename the generated System class (and all references to it) in the Reference.cs file, then add a [XmlRoot(ElementName = "System")] attribute to it so it will be (de)serialized properly.
You'll of course lose these changes when you regenerate the proxy.

Properties does not exist in the current context

I have to store some strings in the Settings file of my project. However, I am not able to access the Settings file to store the strings.
I definitely have accessed Properties file in an earlier project without facing any problems to store values.
Properties.Settings.Default.test = ...
MyApp.Properties.Settings.Default.test = ...
But here in the current project, I am constantly being driven mad by getting the Properties does not exist in the current context
Is there any setting or something that has changed because of which Properties does not appear in Intellisense?
I had this same problem occur when I had been copying and pasting code for plug-ins. It turns out that I had accidentally left the namespace of the other project in place when I copied. By changing the namespace back to the appropriate project, I was able to use the Properties.
at compile-time, Visual Studio generates a c# class which allows access to user and application settings. the generated class is defined in the default namespace specified in the project settings.
you may have to prefix any access to the Properties namespace with the default namespace defined in the project settings;
or you may change the default namespace: go to project settings, application tab, and edit the default namespace of the project.
Make sure your project has a settings file by going to the project properties and clicking on the Settings tab. If there is no settings file, it will tell you so and provide you with the option to create one.
I had this error when I accidentally had the wrong namespace as the Default namespace in the project properties.
To choose the default namespace, right click the project in the Solution ExplorerProperties->Application tab->Default namespace and check that it matches the namespace of your .cs files:
[...]
using System.Text;
using System.Threading;
namespace Correct.Namespace //<-- should match Default namespace field
{
static class Program
{
[...]
In my case, i have referenced a resource that has an Internal/Public access modifier. I have changed its access modifier to Public and the problem was gone.
First, try to recreate your project from scratch, if it's your testing environment. This step will recreate default namespace properly. You may skip this step if you are confident with your namespace configurations.
Second, if you still get Properties unrecognize as in my example where im trying to get data from sqlCon.
string connectionString = Properties.Settings.Default.sqlCon;
go to Project -> EventsandDelegates Properties as shown in the picture below. Make sure to create default settings file.
As soon as you create default settings under your Application settings, in my case it's SQL connection variable. Properties error will go away.
I just had the same problem. But the problem occured when I added a new setting to an already defined settings file (created a long time ago). Somehow adding a setting to the settings file made Visual Studio change the setting's namespace to the project default namespace (which had changed since the settings where modified last time).
So, because the settings access modifier was set to Internal, and the class trying to access the settings still where in the old previous namespace (still in the same project though), the settings became invisible from that class.
Quickest Solution i can offer is to double click on your resources.resx file if it exists, than change the Access Modifier Property at the top of the window from Internal to Public, Rebuild, which should compile successfully, then switch it back to internal and rebuild again. Should be fine after that.
In my case I was referencing one project (A) from another (B). Both in the same solution.
A has a public class (AClass) with a public static method. (AMethod)
I wanted to Test the results of this AClass.AMethod(...)
Visual Studio "colored" AClass in the call AClass.AMethod(...)
and I could right-click AClass and "Go to Definition",
which took me either directly to the source if I added referenced to the "Solution" project
Or to the DLL "outline" if I added reference to the DLL created by building Project "A"
But when I tried to build project "B" I got the error "AClass does not exist in current context"
It turns out Project B was targeting 4.5 and Project A was targeting 4.5.2
This answer helped: https://stackoverflow.com/a/15556365/1175496
Make sure you can see your setting in Settings.Designer.cs file. If not, try deleting and reentering the setting. For some reason, sometimes, the code auto generated by the tool does not include your setting. In that case, the setting wont be available in intellisense.
Funny, but in my case, I had defined the Properties in one project in the solution and was trying to access from another.
Hope this might help someone.
My issue with the "does not contain a definition for 'Properties'", was caused by adding a class to the namespace (JsonBreaker), with the same name as the namespace (ie JsonBreaker.JsonBreaker). Its notable that it was breaking compilation, as it seems some other folks are having a different experience.
namespace JsonBreaker {
public class JsonBreaker {
private readonly Options _opt = null;
...
I just changed the classname (and .cs filename) to Breaker, and my JsonBreaker.Properties.Settings.Default["InteractiveMode"] call started compiling again.
namespace JsonBreaker {
public class Breaker {
private readonly Options _opt = null;
...
I had this problem when running my web project in Visual Studio 2019. After unsuccessfully trying some of the solutions here, I closed VS2019 and re-opened the project from VS2017. Now the Properties namespace is being recognised.
My case:
I added a new database in the Solution Explorer
I tried:
string connectionString = Properties.Settings.Default.SlovickaSQLConnectionString;
My error:
I get:
Properties does not exist in the current context
Here is why:
I forget to add a new dataset in Data Sources panel.
This dataset has to be connected to the previously added database.
And now it works..

.Net WSDL command line utility error

I'm pointing the .Net command line WSDL utility that ships with Visual Studio 2005 at a web service implemented in Java (which I have no control over) and it spits out the following error:
WSDL : error WSDL1: Unable to cast object of type 'System.Xml.XmlElement'
to type 'System.Web.Services.Description.ServiceDescriptionFormatExtension'.
Yet if I point Visual Studio 2005 itself at the service via the Add Web Reference dialog it generates a proxy class for me just fine.
I'm using the WSDL utility to generate all my other service proxies just fine (though an old one does emit a bunch of warnings).
Currently I'm pointing the WSDL utility at the URLs of deployed web services. All of which were developed in Java.
I want to use the WSDL command line utility in the build process to ensure I have the most up-to-date proxy code each time I compile.
Try specifying the option protocol SOAP12
/protocol:protocol (as show on MSDN)
Specifies the protocol to implement. You can specify SOAP (default), HttpGet, HttpPost, or a custom protocol specified in the configuration file. When using the /parameters option, this value is the element and contains a string.
If that does not help then.......
Visual Studio's "Add Web Reference" calls the WSDL.exe when adding a web reference. Basically there is no difference, other then the control you retain when running the WSDL.exe command from the command line. I would suspect that one of your arguments is incorrect or different then the one Visual Studio is setting.
To test this you would need to compare the output for from the 2 different XSD files that are generated, that will give you more of a clue of what is wrong(as Klathzazt has suggested).
Good Luck
Is this an XSD File? files have dependencies. Download the dependency files and place them side/by/side with the XSD you downloaded.
I would assume visual studio may fetch dependencies.
If this doesn't solve it, please provide more details.
I was able to get rid of the this error by decorating the (concrete)Service with the ServiceBehavior, and giving it a Namespace.
using System.ServiceModel;
[ServiceBehavior(Name = "MyConcreteServiceName", Namespace = "http://www.mycompany.com/services/")]
public class MyConcreteService: IMyService
{
}
NOTE:
Set via ServiceBehavior attribute on the service class (and not the contract (interface))
Instead of this:
<wsdl:definitions name="MyConcreteServiceName" targetNamespace="http://tempuri.org/">
I got this:
<wsdl:definitions name="MyConcreteServiceName" targetNamespace="http://www.mycompany.com/services/">

Categories

Resources