Error when create a instance of WebService - c#

I have a WebService that when I use the instance of this webservice, occurs the following error
// Instance of WebService
ServicoZap.EnvArqSenhaSoapClient envia = new ServicoZap.EnvArqSenhaSoapClient();
Error:
Could not find default endpoint element that references contract
'Contract Name' in the ServiceModel client configuration section. This
might be because no configuration file was found for your application,
or because no endpoint element matching this contract could be found
in the client element.
In my app.config the reference is OK.
But to test the webservice, I'm using another project in my solution, called Test.
In this project (Test), I don't have an app.config (I don't know if was necessary).
Can help me ?

You need the app.config in the test project too in this case - copying it over to the test project is one way to fix this

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

Calling a Webservice from a C# Class Library

I have created a class library - MyNS.MyClass. The Library has a Service Reference to a Webservice (added through Add Service Reference) - the Service Reference shows up as MyNS.VS in the Project. The class library is MyNS.dll. MyClass has a static method myStaticFunc which calls the Web Service
I have a separate C# console application where I add reference to this DLL. I have code there calling MyNS.MyClass.myStaticFunc. My project compiles fine. But when I run it, I get an exception
{"Could not find default endpoint element that references contract
'VS.MyObj' in the ServiceModel client configuration section. This
might be because no configuration file was found for your application,
or because no endpoint element matching this contract could be found
in the client element."}
To get rid of this exception, I have to also add a Service Reference in my Console Application & give it the same name (VS - however, here the namespace would obviously be my client app's namespace).
I don't understand why this needs to be done - it's the Library which is calling the WebService - the app is not calling it directly - and the Library does have the Service Reference. And why does the workaround work - in spite of the namespaces being different?

Web Reference Service Error

I am trying to add a web reference service in an ASP.net MVC project.
However when I add the service I got following error,
Custom tool error: Unable to import WebService/Schema. The object
'Settings' already contains a property
'FreeLance_Web_VATService_checkVatService' not of type
WebServiceUrl. C:\FINALBUILD\User Portal\User.Web\Web
References\VATService\Reference.map
Some How the designer.settings.cs had already a service referenced with the same. Once I changed the name of the service and added again, it started working.
I tried all of the above and I still experienced this issue. It turns out that a reference was stored in my app.config. I got rid of it and then re-added the web refences. That fixed the problem.
What you can do is remove the existing services and try to re-add the reference to the mvc application.Other thing is try to search with the 'FreeLance_Web_VATService_checkVatService' name in the settings.cs and see what it has. There should not be same name for the objects which will lead to this conflict
I had the same issue as I had copied the configuration from another file. I had to delete the configuration and update the web reference. When you add web reference settings is automatically added to the configuration file and hence you should not copy that part from another file. Remove and from your configuration file,update web reference and check if it is recreated.

Error on adding a web service to project library as a service reference

I am adding a webservice to a web project as a service reference. The error on adding which occurs on adding is
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved.
Before adding the webservice as a service reference I tried adding it as web reference.On doing it there was no error but, i was not able to access a class through the web reference.
So I went for the option of service reference.
I was able to add service reference to a web project and every thing works fine but I am unable to do the same in a class library.
Your help will be appreciated..
Thanks
Right click on your service in Solution Explorer and select View in browser.
you may have some errors in your service and in this way you can find out the errors.

Generating the System.ServiceModel configuration section for WCF Data Service client

When I use the "Add Service Reference" utility in Visual Studio to connect to a WCF Data Service (OData), visual Studio doesn't generate an App.config file with the System.ServiceModel section for me. (The proxy class is generated fine). Is this normal?
Is there still a way to have this config generated automatically? The WCF service in question is secured and I therefore struggle with authentication issues if I try to to use the command line svcutil.exe with the /config option.
svcutil.exe cannot be used with WCF Data Services (OData), there's a datasvcutil.exe which is used instead.
The Add Service Reference for OData should not generate anything into your app.config as it doesn't need it. To use it, you just new up the generated context class and pass in the URI of the service.
If your OData endpoint required authentication though, the Add Service Reference doesn't support that though, so I'm surprised it works for you.

Categories

Resources