I'm working with an interface generated by from a wsdl, and I'm running into an issue when trying to host my service as a Windows Service.
The following line appears above the interface. Unless I change it from
[System.ServiceModel.ServiceContractAttribute(Namespace="http://xxxxxx.com/", ConfigurationName="IService")]
to
[System.ServiceModel.ServiceContract]
I can't start the Windows service that hosts my program (the error log in the event viewer says the contract IService could not be found in the list of contracts implemented by Service.) I'm listing the endpoint my app.config file as follows:
endpoint address=""
binding="basicHttpBinding"
contract="Service.IService"
This also happens when I change the contract to "http://xxxxxxx.com/IService" as it appears in the ServiceContractAttribute. Any ideas about how I can fix this?
The service portion of the config file:
<service name="Service.Service"
behaviorConfiguration="myServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Service"/>
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="Service.IService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="Service.IService" />
</service>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
The contract attribute of the endpoint element in config needs to match the value of the ConfigurationName property of the ServiceContractAttribute in the code. So in your case just change the config so that it reads contract="IService" and you should be good.
It appears that it can't find the endpoint. Have you used a terminal to interrogate the endpoint to see if it is responding at the supplied address?
"itowlson" is most likely on the right track with his comment - your original service contract defines a configuration name:
[ServiceContract(Namespace="http://xxxxxx.com/",
ConfigurationName="IService")]
but there is no such service configuration in your config section.
Try changing this:
<service name="Service.Service"
to
<service name="IService"
(or alternatively, change the ServiceContract to:
[ServiceContract(Namespace="http://xxxxxx.com/",
ConfigurationName="Service.Service")]
These two names need to match! Or simply leave out the configuration name from the service contract:
[ServiceContract(Namespace="http://xxxxxx.com/")]
and in this case, the service config will be found based on the Namespace.ServiceClassName pattern of the service class that actually implements the service contract.
Either way, you need to make sure the information in the ServiceContract attribute and the config file match up.
Marc
Related
I have been digging for hours to solve this problem, but have not gotten anywhere.
I am attempting to configure a service and everything compiles, but I am getting some warnings and the service cannot be found when attempting to create a reference.
The specific messages are:
WCF configuration validation warning: The 'name' attribute is invalid - The value 'VisionProRegistrationService.VisionProRegistrationSvc' is invalid according to its datatype 'serviceNameType'.
and
WCF configuration validation warning: The 'contract' attribute is invalid - The value 'VisionProRegistrationService.IVisionProRegistrationSvc' is invalid according to its datatype 'serviceContractType'.
The config file code is as follows:
<system.serviceModel>
<services>
<service behaviorConfiguration="VisionProRegistrationService.VisionProRegistrationServiceBehavior" name="VisionProRegistrationService.VisionProRegistrationSvc">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="" name="NetTcpBinding_IVisionProRegistrationService" contract="VisionProRegistrationService.IVisionProRegistrationSvc">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="MexBinding_IVisionProRegistrationService" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8527/VisionProRegistrationService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VisionProRegistrationService.VisionProRegistrationServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="mexbehavior">
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
The contract looks like this:
namespace VisionProRegistrationService { [ServiceContract] public interface IVisionProRegistrationSvc { [OperationContract] bool Initialize(ServiceDataContracts.ModuleConfigurationData config, List<ServiceDataContracts.TcpClientData> clients,
string savedJobFilePath = null, string savedCalFilePath = null, int savedExposureTimeUs = 250, bool savedStrobePulseHi = true);
And finally, the service class itself looks like this:
namespace VisionProRegistrationService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class VisionProRegistrationSvc : IVisionProRegistrationSvc
{
This is not posting as cleanly as I would like, but I hope it is enough.
Everything I had found in the past indicated a mismatch with the interface or class name, but those all seem correct. I can't find anything officially on this. Does anyone have any suggestions?
Thanks!
Running the test client provided the information I needed to solve the problem. One of the classes in the data contract contained multidimensional arrays. Thanks for the help! I was not getting anywhere without the more detailed debugging information.
So here is my problem. I have a client that is utilized within a service, and when I test said service using the built-in test host in Visual studio, all of the service contracts are available. But, when I try to test one of the service contracts, Visual studio spits out the following error
Could not find default endpoint element that references contract 'TestServiceReference.ITestService' 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.
Now, I know the immediate and obvious answer is to check my config to make sure that my endpoint is correct, but that is the thing, it is correct. I checked both the web.config for the service implementing the client, and the app.config for the client. Both endpoints are correct(at least I think they are).
Here is the web.config endpoint:
<endpoint address="http://testServiceRepo/TestServices/TestService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
Here is the app.config endpoint:
<endpoint address="http://testServiceRepo/TestServices/TestService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
The endpoints are the exactly the same, and they both reference TestServiceReference.ITestService. So, I am at a loss here. What would you guys suggest?
Thanks for any help!
This error can arise if you are calling the service in a class library and calling the class library from another project. In this case you will need to include the WS configuration settings into the main projects app.config if its a winapp or web.config if its a web app. how you are testing it ? Did you tried to create client proxy/class using svcutil and then test these methods. it also generates require configuration in output,config file which you can use.
Try settings like this:
client config:
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestService" />
</basicHttpBinding>
<client>
<endpoint
address="http://testServiceRepo/TestServices/TestService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
</client>
server config:
<basicHttpBinding>
<binding name="BasicHttpBinding_ITestService" />
</basicHttpBinding>
<behaviors>
<serviceBehaviors>
<behavior name="testBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="testBehavior" name="TestServiceReference.TestService">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
</service>
</services>
EDIT
Note: Actually if you are using service reference (generated proxy) it is enough to fix the settings of service, delete the content of <system.serviceModel> tag in client, and add/update your service reference. It will fix up your settings in the client's config file.
For me this exact issue happened when I accidentally 'fixed' the WCF endpoint as
<client>
<endpoint
address="http://testServiceRepo/TestServices/Testservice.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
</client>
instead of
<client>
<endpoint
address="http://testServiceRepo/TestServices/TestService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ITestService"
contract="TestServiceReference.ITestService"
name="BasicHttpBinding_ITestService" />
</client>
(notice the lowercase 's' in the word TestService first address example)
This was for a c# project
I have created a wcf service, but when I run , then it show error like this.
I have change the name class and interface name using rename tool.
Here is code for service.cs class
public class MyTest : MyServices
{
public string MyTask1(string a)
{
return "Hello " + a;
}
public string MyTask2(DataContract1 dc)
{
return "Hello " + dc.fname;
}
}
Here is the code for my interface :
[ServiceContract]
public interface MyServices
{
[OperationContract]
string MyTask1(string myValue);
[OperationContract]
string MyTask2(DataContract1 dcValue);
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class DataContract1
{
string firstName;
string lastName;
[DataMember]
public string fname
{
get { return firstName; }
set { firstName = value; }
}
public string lname
{
get { return lastName; }
set { lastName = value; }
}
}
I have edited my web.config file, and added these lines (I read it in black book)
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!--Service EndPoints-->
<endpoint address="" binding="wsHttpBinding" contract="MyServices">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadatExchange"/>
</service>
Here is my system.servicemodel code
<system.serviceModel>
<services>
<!-- My Custimization -->
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!--Service EndPoints-->
<endpoint address="" binding="wsHttpBinding" contract="MyServices">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadatExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
1) in legacy web service we create proxy using wsdl. WSDL expose web service meta data. in wcf another term comes that mex endpoint which also expose meta data but wsdl is still live in wcf.i am new in wcf hence i am confusing what is the difference between wsdl & mex endpoint?
It's pretty the same thing but mex is designed to support non-HTTP protocols and for advanced configuration/security scenarios. WSDL is the legacy way and MEX is the new improved version with WCF.
2) what is the meaning of httpGetEnabled="false" or httpGetEnabled="true"
It will expose metadata via wsdl through the defautl url, even if you don't have defined a mex endpoint for your service.
3) if i set httpGetEnabled="false" then what will happen? does it mean that client will not be able to add service reference from IDE? but i set httpGetEnabled="false" and saw client can add service reference. so it is very confusing for me that what httpGetEnabled is false or true does ?
A client can add a reference in VS only if httpGetEnabled/httpsGetEnabled is enable or if you have define a mex endpoint in the configuration of your service. The best practice is to expose metadata on dev environnement but not on production. You can also distribute your service contracts via separate assemblies and use ChannelFactory.
4) one guy said :- MEX and WSDL are two different schemes to tell potential clients about the structure of your service. So you can choose to either make your service contracts public as (MEX) or WSDL. if the above statement is true then tell me when to use MEX & when to use WSDL?
A WSDL is generally exposed through http or https get urls that you can't really configure (say for security limitations or for backward compatibility). MEX endpoints expose metadata over configurable endpoints, and can use different types of transports, such as TCP or HTTP, and different types of security mechanisms.
So MEX are more configurable, while WSDL is more interoperable with older versions of clients and non-.net clients that work with WSDLs.
5) how could i disable mex and expose my service through only WSDL
Do not specifiy a mex endpoint in your config and use httpGetEnabled
6) WSDL support all bidning like wshttp,wsdualhttp or tcp etc...
Exposing metadata is totally different that invoking the service.
UPDATE
re you try to mean that there should be no mex endpoint related entry in config and httpgetenable would look like
Yes, you don't have to specify a mex endpoint AND httpGetEnabled. Only one is required to expose metadata. Do not specifiy httpGetUrl as this is depending on your hosting environment.
you said mex is configurable but wsdl is not. what r u trying to means mex is configurable...please discuss what kind of configuration mex support & how to configure.
MEX endpoints are special endpoints that allow clients to receive the service’s metadata by using SOAP messages instead of http get requests. You can create MEX endpoint that can be accessed through http, https, tcp, and even named pipes. HttpGetEnable allow you to expose metadata through HTTP GET method, usually the service’s address with the suffix of ‘?wsdl'
MEX and WSDL both output nearly the same thing.
In most cases there is no need for MEX endpoint – using WSDLs with http get is usually enough.
I understand your intention to understand this part, but do not spend to many times on this : there are so many others complicated features !
Spelling mistake I guess..
IMetadatExchange -- > IMetadataExchange
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadatExchange"/>
try this...
<system.serviceModel>
<services>
<!-- My Custimization -->
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!--Service EndPoints-->
<endpoint address="" binding="wsHttpBinding" contract="MyServices">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
I've searched and wasted all day trying everything I can think of or find to resolve this issue: I built my first WCF service and thought it would be cool to host it in IIS. It's a long-running service, so that's a no-go. I have since added another project to my solution to host the WCF service with, referenced the WCF project, and have been met with constant struggle trying to host from code.
I largely followed http://msdn.microsoft.com/en-us/library/ms733069.aspx for guidance on implementing the host, with minor tweaks for my specific situation.
The current challenge is simply getting the service endpoint defined in the hosting project's App.config. It cannot resolve the "contract" attribute of an "endpoint" to my WCF service contract.
WCF Assembly
namespace WcfFoldingService
{
[ServiceContract(SessionMode=SessionMode.Required, CallbackContract=typeof(IFoldingUpdaterClientContract))]
public interface IFoldingUpdaterServiceBehavior
{
[OperationContract(IsOneWay = false, IsInitiating = true)]
void Subscribe();
[OperationContract(IsOneWay = false, IsTerminating = true)]
void Unsubscribe();
[OperationContract(IsOneWay = true)]
void PublishSomeOperation();
}
public interface IFoldingUpdaterClientContract
{
[OperationContract(IsOneWay = true)]
void SomeOperation();
}
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession, ConcurrencyMode=ConcurrencyMode.Single)]
public class FoldingUpdaterService : IFoldingUpdaterServiceBehavior
{
// Omitted for brevity, but complete implementation exists.
}
}
/WCF Assembly
Hosting Assembly
App.config
<system.serviceModel>
<services>
<service name="WcfFoldingService.FoldingUpdaterService" behaviorConfiguration="httpServiceBehavior">
<endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="ServiceBindingConfiguration" contract="WcfFoldingService.IFoldingUpdaterServiceBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<protocolMapping>
<add scheme="http" binding="wsDualHttpBinding" bindingConfiguration="ServiceBindingConfiguration"/>
</protocolMapping>
<bindings>
<wsDualHttpBinding>
<binding name="ServiceBindingConfiguration">
<reliableSession ordered="true"/>
<security mode="None"/>
</binding>
</wsDualHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="httpServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
<serviceThrottling maxConcurrentCalls="1000" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
<sendMessageChannelCache allowUnsafeCaching="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
/Hosting Assembly
Message:
The 'contract' attribute is invalid - The value 'WcfFoldingService.IFoldingUpdaterServiceBehavior' is invalid according to its datatype 'serviceContractType' - The Enumeration constraint failed.
I'm stumped. Google offers few relevant links, and they mostly have to do with other configuration issues that I am not experiencing. The WCF assembly is referenced, I am using fully qualified names, I even tried using the ConfigurationName attribute in case there was a namespace conflict somehow. I'm new to WCF so I'm hopeful that this is an obvious problem!
Edit:
I am now using programmatic configuration rather than App.config XML. The most significant statement is ContractDescription.GetContract(serviceType), as even new ContractDescription("FullNamespace.IContract") failed exactly as the XML configuration did. The Type object for serviceType's FullName property is exactly the same as my "FullNamespace.IContract". I suspect an issue with the assembly not being loaded without a hard reference to it in code, but I cannot be certain at this point. For now, this approach will work fine:
using (var host = new ServiceHost(typeof(FoldingUpdaterService), baseAddress))
{
var serviceType = typeof (IFoldingUpdaterServiceBehavior);
var serviceContract = ContractDescription.GetContract(serviceType);
var foldingEndpoint = new ServiceEndpoint(serviceContract)
{
Binding = new WSDualHttpBinding()
Address = new EndpointAddress(new Properties.Settings().WcfUpdaterServiceAddress)
};
host.Description.Endpoints.Add(foldingEndpoint);
[...]
This is an old question, but in case someone has the same problem, this worked for me:
Try closing Visual Studio and deleting the .suo file located at the same directory as your solution file (.sln). This resets the editors cache. I had the same problem after I moved the service contract file to a different assembly and the cache still referred to the old location.
The self-hosting application will need <host> tag inside <service> tag:
<system.serviceModel>
<services>
<service name="WcfFoldingService.FoldingUpdaterService" behaviorConfiguration="httpServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Services/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="ServiceBindingConfiguration" contract="WcfFoldingService.IFoldingUpdaterServiceBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
I don't know if this still an issue to you, but stumbled upon the same problem recently and it might be of some help.
When specifying your Service Name, you have to use your Namespace as well. So lets say your Namespace would be myhost then the correct entry would be ...
<service name="myhost.WcfFoldingService.FoldingUpdaterService"...>
The same applies to the contract.
My solution, created with VS2012, contained several .NET 4.0 projects. I switched to VS2013, and when I added a new WCF library project, it was created with .NET 4.5. Resetting the new projects to .NET 4.0 solved my problem.
Make sure that you made a Reference of the service application in the host
maybe you can help me set up my WCF service.
First, here is my config file:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings />
<services>
<service name="AuthenticatorService.Authenticator">
<endpoint address="auth" binding="basicHttpBinding" bindingConfiguration=""
name="AuthEndpoint" contract="AuthInterface.IAuthenticator" />
<endpoint address="mex" binding="mexHttpBinding" name="MetadataEndpoint"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
And this is how I call my service from c#:
//This creates a link to the WCF service using basicHttpBingind
httpFactory = new ChannelFactory<IAuthenticator>(new BasicHttpBinding(), new EndpointAddress("http://myUrl/auth.svc"));
httpProxy = httpFactory.CreateChannel();
It worked fine when I was doing this on localhost but now it keeps telling me no endpoint was found.
Also, the server generated the following error:
System.ServiceModel.EndpointNotFoundException: There was no channel actively listening at 'http://myURL/auth.svc/$metadata'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening.
Im really confused, I have no idea why this is happening. Do I need to create another service file for the metadata exchange?
Do I need to set a baseAddress?
Thanks
How did you deploy the service? I assume the service is running in IIS on your box - did you try hitting the service URL (http://myUrl/auth.svc) in a browser to see if it is indeed up?