Adding a WCF Service Reference - c#

I'm having some issues adding a WCF service reference on a project which is not set as the "StartUp Project". I keep getting "Could not find default endpoint element that references contract ....". and I tried adding the same WCF service reference on my StartUp project and it works fine.
Here's the current app.config client configuration that I use:
<client>
<endpoint address="http://host:8080/library"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ILibrary"
contract="ServiceReference.ILibrary" name="WSHttpBinding_IAccountAccess">
</endpoint>
</client>
not really sure what I'm missing or doing wrong and I already tried entering the complete namespace of the project as the contract.
Thanks,

Related

WCF service endpoint configuration doesn't like the binding attribute

In my web.config file I have the following service defined:
<services>
<service name="ShareYourWage.Service.WageService" behaviorConfiguration ="metadataBehavior">
<endpoint>
binding="basicHttpBinding"
contract="ShareYourWage.Service.IWageService">
</endpoint>
</service>
</services>
Yet, when I debug the service, the test client throws the following error:
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
and digging into the specific error points to the endpoint section shows the following error:
The configuration section cannot contain a CDATA or text element.
I've Googled this error and the MSDN site and have used their examples and still have this problem. A 2nd pair of eyes would be big help, thanks!
You accidentally closed your endpoint tag before the binding and contract attributes.
Remove the '>' at the end of <endpoint>.
You want it to be like this:
<endpoint
binding="basicHttpBinding"
contract="ShareYourWage.Service.IWageService">
</endpoint>
If you're using Visual Studio or some other XML-aware text editor to modify the config files, the syntax highlighting can be helpful for spotting these kinds of problems.

Configure Service Reference... - Object reference is not set to an instance of an object

I am working with Visual Studio 2013, .NET4.5.
Originally I was WCF service consumer but due to lack of resources in team that deals with subsystem I took over development of both sides of WCF service. So I got Code of the WCF service that I need to call and now trying to plug it in to debug it on my local system.
Issue: Service that I need to call works on localhost fine I can get wsdl and browse to it.
However when I try in Visual Studio 2013 'Configure Service Reference...' and Try to change url from dev server to local it gives me Object reference is not set to an instance of an object error.
Has anyone experienced something similar?
What is causing this?
How do I fix it?
Solved myself by deleting Service Reference, and then adding new Service Reference with given URL.
I know this is a bit late but I had a similar problem and I fixed it by adding
an identity element to the app.config file for the service's endpoint. Example:
<identity>
<userPrincipalName value="username#domain" />
</identity>
The for me it worked even with an empty value for userPrincipalName:
<identity>
<userPrincipalName value="" />
</identity>
Full endpoint element:
<endpoint address="net.tcp://localhost:9876/my-service/tcp" ... >
<identity>
<userPrincipalName value="" />
</identity>
</endpoint>

Server Error in '/' Application

I got this error when trying to access a Service
The type 'WebRole1.RestServices.RegisterService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
This is linked to the definition on the Web.config file
I defined my service like this:
<!-- Service Authenticate -->
<service name="System.Web.ApplicationServices.AuthenticationService" behaviorConfiguration="AuthenticationServiceBehaviors">
<endpoint contract="System.Web.ApplicationServices.AuthenticationService" binding="basicHttpBinding" />
</service>
<!-- Service Register -->
<service name="WebRole1.RestServices.RegisterService" behaviorConfiguration="RegisterServiceBehaviors">
<endpoint contract="WebRole1.RestServices.IRegisterService" binding="basicHttpBinding" />
</service>
The definition working for the Authenticate Service but not for the Register Service.
I am not sure about the name i should put for the service but WebRole1.RestServices is the namespace for the RegisterService.svc
I am sure the error is from the Web.config file. Anyone has an idea how to correct this.
Thx.
Follow these steps from within Visual Studio:
Right click your service file
Select the View Markup option
Change the value of the Service
attribute to reflect the fully
qualified path of the underlying
service type.
Make sure the CodeFile attribute value is also correct
This happens because when you rename the service type in code it doesn't automatically update the service mark-up directive values appropriately, or at all for that matter.

Consuming a WCF Service

I created a WCF service which is hosted in windows service. I created a proxy using svcutil
“svcutil.exe http://localhost:8000/ServiceModelSamples/FreeServiceWorld?wsdl”
It generated an output.config file and proxy class.
The output.config has the following element
<client>
<endpoint address="http://localhost:8000/ServiceModelSamples/FreeServiceWorld"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IWeather"
contract="IWeather" name="WSHttpBinding_IWeather">
<identity>
<servicePrincipalName value="host/sdfsf.sdfs.com" />
</identity>
</endpoint>
</client>
I created a website (as client) and added a new C# file (MyFile.cs) into it. I copied the contents of the proxy class into MyFile.cs.
[The output.config is not copied to the web site]
In the code behnid of aspx, I am using the following code
WeatherClient client= new WeatherClient("WSHttpBinding_IWeather");
It throws an exception as “Could not find endpoint element with name 'WSHttpBinding_IWeather' and contract 'IWeather' in the ServiceModel client configuration section.”
Could you please help me to understand the missing link here?
You need to add the elements in output.config to the web.config of the web site for the client to know where to look for the service. If the client isn't running on the same machine as the service you will need to exchange localhost for the IP address or host name of the machine running the service.

WCF Error - Could not find default endpoint element that references contract 'UserService.UserService'

Any ideas how to fix this?
UserService.UserServiceClient userServiceClient = new UserServiceClient();
userServiceClient.GetUsersCompleted += new EventHandler<GetUsersCompletedEventArgs>(userServiceClient_GetUsersCompleted);
userServiceClient.GetUsersAsync(searchString);
.
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_UserService"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:52185/UserService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_UserService"
contract="UserService.UserService"
name="BasicHttpBinding_UserService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="Shell.Silverlight.Web.Service3Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="Shell.Silverlight.Web.Service3Behavior"
name="Shell.Silverlight.Web.Service3">
<endpoint address=""
binding="basicHttpBinding"
contract="Shell.Silverlight.Web.Service3" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Could not find default endpoint element that references contract 'UserService.UserService' 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.
Resolved!
I didn't mention that this was a Silverlight application. I had the wcf reference in a DLL which had it's own "ServiceReferences.ClientConfig" file. I moved the contents of the DLL's ServiceReferences.ClientConfig to the main silverlight project and it worked.
I had a run in with the same problem. My application was also a Silverlight application and the service was being called from a class library with a custom UserControl that was being used in it.
The solution is simple. Copy the endpoint definitions from the config file (e.g. ServiceReferences.ClientConfig) of the class library to the config file of the silverlight application. I know you'd expect it to work without having to do this, but apparently someone in Redmond had a vacation that day.
You can also set these values programatically in the class library, this will avoid unnecessary movement of the config files across the library.
The example code for simple BasciHttpBinding is -
BasicHttpBinding basicHttpbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
basicHttpbinding.Name = "BasicHttpBinding_YourName";
basicHttpbinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
basicHttpbinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endpointAddress = new EndpointAddress("http://<Your machine>/Service1/Service1.svc");
Service1Client proxyClient = new Service1Client(basicHttpbinding,endpointAddress);
Just in case anyone hits the same problem whilst using WPF (rather than WCF or Silverlight):
I had this error, when connecting to a Web Service. When my code was in the "main" WPF Application solution, no problem, it worked perfectly. But when I moved the code to the more sensible DAL-layer solution, it would throw the exception.
Could not find default endpoint element that references contract 'MyWebService.MyServiceSoap' 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.
As has been stated by "Sprite" in this thread, you need to manually copy the tag.
For WPF apps, this means copying the tag from the app.config in my DAL solution to the app.config in the main WPF Application solution.
I ran into the same issue, for whatever reason Visual Studio did not update the web config when I first added the service. I found that updating the Service Reference also fixed this issue.
Steps:
Navigate to the Service Reference Folder
Expand it
Right Click and Select update Service Reference
Observe web Config be updated
Change the web.config of WCF service as "endpoint address="" binding="basicHttpBinding"..." (previously binding="wsHttpBinding")After build the app, in "ServiceReferences.ClientConfig" ""configuration> has the value. Then it will work fine.
Rename the output.config produced by svcutil.exe to app.config.
it worked for me.
Do you have an Interface that your "UserService" class implements.
Your endpoints should specify an interface for the contract attribute:
contract="UserService.IUserService"
Not sure if this is an issue.
Endpoint and binding both have the same name
Not sure if it's really a problem, but I see you have the same name for your binding configuration ().
I usually try to call my endpoints something like "UserServiceBasicHttp" or something similar (the "Binding" really doesn't have anything to do here), and I try to call my binding configurations something with "....Configuration", e.g. "UserServiceDefaultBinding", to avoid any potential name clashes.
Marc
Had to add the service in the calling App.config file to have it work. Make sure that you but it after all . This seemed to work for me.
This problem occures when you use your service via other application.If application has config file just add your service config information to this file.
In my situation there wasn't any config file so I use this technique and it worked fine.Just store url address in application,read it and using BasicHttpBinding() method send it to service application as parameter.This is simple demonstration how I did it:
Configuration config = new Configuration(dataRowSet[0]["ServiceUrl"].ToString());
var remoteAddress = new System.ServiceModel.EndpointAddress(config.Url);
SimpleService.PayPointSoapClient client =
new SimpleService.PayPointSoapClient(new System.ServiceModel.BasicHttpBinding(),
remoteAddress);
SimpleService.AccountcredResponse response = client.AccountCred(request);
For those who work with AX 2012 AIF services and try to call there C# or VB project inside AX (x++) and suffer from such errors of "could not find default endpoint"... or "no contract found" ...
go back to your visual studio (c#) project and add these lines before defining your service client, then deploy the project and restart AX client and retry:
Note, the example is for NetTcp adapter, you could easily use any other adapter instead according to your need.
Uri Address = new Uri("net.tcp://your-server:Port>/DynamicsAx/Services/your-port-name");
NetTcpBinding Binding = new NetTcpBinding();
EndpointAddress EndPointAddr = new EndpointAddress(Address);
SalesOrderServiceClient Client = new SalesOrderServiceClient(Binding, EndPointAddr);
In case if you are using WPF application using PRISM framework then configuration should exist in your start up project (i.e. in the project where your bootstrapper resides.)
In short just remove it from the class library and put into a start up project.

Categories

Resources