Server Error in '/' Application - c#

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.

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.

How to set matching WCF service names in both Web.Config file and in the .svc ServiceHost

I have a silverlight application with a WCF service that has its .svc ServiceHost like below
<%# ServiceHost Language="C#" Debug="true" Service="App1.Web.GetData"
CodeBehind="GetData.svc.cs" %>
With the service tag defined as below under my web.config file's system.serviceModel section.
<services>
<service name="App1.Web.GetData">
<endpoint address="" binding="customBinding" bindingConfiguration="App1.GetData.customBinding0" contract="App1.GetData" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
In my development environment, a client can successfully connect to the service, but once deployed in production, i have to first modify the service name="App1.Web.GetData" i.e remove "Web" such that itsservice name= "App1.GetData", only then will the service be found by the client silverlight application.
But as you can abserve, that creates a mismatch between the ServiceHost name in the .svc file and the service name in the web.config file.
And then i read from the link below this quote in Carlos Figueira reply.
"So if you want the configuration on web.config to apply to your
service, you need to set as the "name" attribute of the
element the fully-qualified name of the service, which is the exact
same name as is used in the "Service" attribute of the ServiceHost
directive in the .svc file."http://social.msdn.microsoft.com/Forums/vstudio/en-US/0c7571eb-2a37-4325-b9d5-4dfa3228c9e7/content-type-applicationsoapxml-charsetutf8-was-not-supported-by-service-error?forum=wcf
And because my Service name in .svc and web.config files are un-matched in production unlike in dev environment, i get the error that i at the following link earlier.
Cannot process the message because the content type 'application/soap+msbin1' was not the expected type 'text/xml

Adding a WCF Service Reference

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,

WCF endpoint configuration: 2nd endpoint doesn't work at all, 1st endpoint doesn't seem affected by binding

In a WCF service hosted in IIS, I'm trying to set up multiple endpoints. One for SOAP and one for SOAP12. Per the MSDN documentation, I've edited Web.config like:
<services>
<service name="MyNamespace.MyClass">
<endpoint address="" binding="basicHttpBinding" contract="IContract" />
<endpoint address="Endpoint2" binding="wsHttpBinding" contract="IContract" />
</service>
</services>
This doesn't seem to have any effect. There is no answer on URL:
http://localhost:51454/MyClass.svc/Endpoint2
If I change IContract to IContract2, I get the error:
The service '/MyClass.svc' cannot be activated due to an exception during
compilation.
So the Web.config I'm editing is the one being used.
Changing the binding for the default address from basicHttpBinding to wsHttpBinding doesn't have any effect. The WSDL stays the same.
The WSDL includes this bit, which seems to suggest that it's running using a generated binding:
<wsdl:service name="TapasSim">
<wsdl:port name="BasicHttpBinding_IContract"
binding="i0:BasicHttpBinding_IContract">
<soap:address location="http://localhost:51454/MyClass.svc"/>
</wsdl:port>
</wsdl:service>
Why does the WCF service not use the configuration from Web.config?
Why does WCF not listen on /Endpoint2 with the SOAP12 binding?
Why does the default endpoint not change from basicHttpBinding to wsHttpBinding?
Try adling a base adress for the endpoint:
<service name="namespace.Service">
<host>
<baseAddresses>
<add baseAddress="http://localhost:51454/myclass.svc"/>
</baseAddresses>
</host>
// endpoint omnited
Or try adding a slash before the address:
endpoint address="/Endpoint2" binding="wsHttpBinding" contract="IContract"
The MSDN article is correct and there is nothing wrong in your configuration. I created a WCF client using VS and was able to successfully call using
http://localhost:51454/MyClass.svc/Endpoint2
Apparently, it does not appear as a valid url from browser. try consuming from a client using the second url and it should work
The problem was the service name:
<service name="MyNamespace.MyClass">
The class name was wrong. When you enter a wrong contract interface, WCF throws an error. But a wrong class name is silently ignored. That explains why it fell back on the default configuration.

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