Using class library with WCF service in ASP.NET 5 - c#

In my project I have a class library that contains connections for WCF services.
In old ASP.NET MVC in order to use service methods I only needed to add bindings in my web.config and it would work properly.
The issue that I am having now is that when I call web service in ASP.NET5 I get this exception:
InvalidOperationException: Could not find default endpoint element that references contract 'xxx' 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.
Is there a way that I can add my binding in a similar way as I would do in old MVC apps?

I'm using the configuration below from an MVC app. When you add a reference to your WCF service using the add service ref dialog. A client section will get added to your System.ServiceModel section in your web.config. It should specify the endpoint which what seems to be missing based on the error you're getting.
Hope this helps
<client>
<endpoint address="http://address.to.your.service.com:8080/V3/ConfigService.svc"
binding="basicHttpBinding"
bindingConfiguration="ConfigService.V3.ConfigHttpServiceBinding"
contract="ConfigService.IConfigService"
name="ConfigService.V3.ConfigHttpService"/>
</client

I was able to run by programattically config bindings. thanks to #wiktor-zychla comment.
var documentService = new DocumentServiceClient(
new BasicHttpBinding(BasicHttpSecurityMode.None),
new EndpointAddress("http://localhost:60205/DocumentService.svc"));

Related

unable to run wcf service app with a renamed service?

I have a basic solution and I've added a WCF service lib. I can view the default service created in the browser after the initial wcf service app has been added to the solution. However, after I rename the default wcf service and its interface class and then view the service in the browser, the web page displays the following runtime error:
The type 'MyNewService.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
However, if I search the project structure for 'Service1' then no references to 'Service1' are returned. Any idea what the root cause of this error might be? It seems like I've been able to do this successfully several times in the past and I don't think that I've ever encountered this roadblock before.
Look in the app.config, look at endpoint->contract, im guessing thats where need to update it.
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.MyService1">
<endpoint address="" binding="basicHttpBinding"
contract="WcfServiceLibrary1.**IMyService1**">
By default, WCF is configured and exposed via the App.config file of your library. Do a search within your App.config to find the old name and change it to the new.
When you want to change the name of your service in the future, use the refactor name (default ctrl+r, r) operation and it will find the name in the config file for you as well.

project that references another project with WCF service reference - default endpoint not found

I have a project called "AppCore" that I am reusing/referencing in several other projects. AppCore had a method for sending mail via system.net that simplifies emailing. However, I created a WCF service reference (to a service that sends mail in a queue) in the AppCore project, created a test form and was able to use the service just fine. When I create a new project (project name "FeedReader") and reference the AppCore project, however, I get an error: "Could not find default endpoint element that references contract" when attempting to access the WCF service. I think this has something to do with the compiler looking for endpoint info in the FeedReader project app.config file and not getting it from the AppCore project app.config file.
If I reference the WCF service directly from the FeedReader project, the endpoint is found. This would be just fine, however I have a dozen or so other projects I wish to have make this same reference and creating a service reference for all of these and future projects makes management difficult and there's no code reuse (something I wish to avoid).
Is this not possible to do (reference a project that references a WCF service)?
In the AppCore project app.config file, you can see the endpoint (it works fine)
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISendMailService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://mailservice:9999/SendMailService.svc/SendMailService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISendMailService"
contract="Service_SendMail.ISendMailService" name="BasicHttpBinding_ISendMailService" />
</client>
</system.serviceModel>
Naturally, the other projects don't have endpoints defined as they are referencing AppCore (of which there is a definition). NOTE: I plan on having another few service references in AppCore - but am stuck at just one for now until I can solve this dilemma.

Invoking a Web Service via DLL getting this error

I get this error when invoking my dll with SAP B1 Integration Framework:
Could not find default endpoint element that references contract
'MobiService.AccountsSoap' in the Service Model 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.
But when I invoke the DLL via another .NET application it works.
My app config is set:
<client>
<endpoint address="http://191.211.42.100/MobiVendWSTest/accounts.asmx"
binding="basicHttpBinding" bindingConfiguration="AccountsSoap"
contract="MobiService.AccountsSoap" name="AccountsSoap" />
</client>**
You need to copy the entire service configuration from the DLL's app.config to your application's app.config, as DLLs can not have their own app.config.
The application will read its app.config and the DLL will automatically find the settings even though there's no separate config file for it.

Error when create a instance of WebService

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

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