WCF endpoint configuration error: contract attribute invalid?

I have a WCF service by calling her UserService . UserService has a link to the class library. Let me call it DoWork.dll . DoWork.dll has a WCF service link to another service that we will call CompanyService .

Now, when I first tried calling UserService , I would have received an error message not configured for the endpoint. After reading over the network, I found that I needed to add CompanyService bindings and client information in the UserService web.config under the <system.serviceModel> node.

Here he is:

 <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IComapnyService" /> </basicHttpBinding> </bindings> <client> <endpoint name="BasicHttpBinding_ICompanyService" address="http://it-dev.company.local:81/Project/Copmpany/CompanyService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IComapnyService" contract="CompanyService.ICompanyService" /> </client> 

I have a problem: contract="CompanyService.ICompanyService" shows an error:

The attribute 'contract' is not valid. The value of "CompanyService.ICompanyService" is not valid according to its data type "clientContractType". Enumeration constraint error.

Now, if I add the CompanyService link directly to the UserService WCF project, the error will disappear (obviously). However, I should not have done this. I tried to fully define the namespace in which the ICompanyService contract is ICompanyService , and this also does not work. I deleted the .suo file and rebuilt the project, and this also does not work (offered elsewhere on the Internet). In addition, if I type contract= , I get a drop-down list, but CompanyService.ICompanyService will not be found anywhere (only when I refer to the service directly in the UserService project).

I tried to configure it using Tools > WCF Service Configuration Editor , and this does not help.

I should note that everything seems to be working fine, but I don't like the fact that intellisense gives me a blue squiggly underscore and this error message. I have a feeling that I need something else in web.config to make it work, as UserService refers to DoWork.dll , which in turn refers to CompanyService , the contract of which I cannot see properly.

Any suggestions are greatly appreciated. Thanks in advance.

+7
web-config wcf wcf-endpoint
source share
1 answer

You are right - you do not need to do this.

The architecture of having a DLL (DoWork.dll) with a service link (ComanyService) is bad. If the DLL does not have a hard-coded client endpoint (in code) to call CompanyService for you, then anyone who uses the DLL will have to try and figure out how to configure the client endpoint for a service that they are not aware of. This is what you are faced with.

The reason this works when you add a service link directly from your UserService is that when you do this, you get a copy of ServiceContract from the CompanyService metadata. To prove this, look in the Reference.cs file that is generated, search for CompanyService, and you will find that it has the [ServiceContract] attribute that identifies it as a WCF service. In addition, you will see the [OperationContract] attributes for these methods, as well as any [DataContracts] services that also change. In other words, all these β€œtypes” were imported into your project, and when you compile, WCF can now find these types when creating the client instance.

If CompanyService is one of your services, consider extracting the ServiceContract definition (interface) to a separate DLL. You can then refer to these types as "assembly references" from the service (CompanyService) and any client applications such as UserService. At least you do not need to add a link to the service. But you still need to fill out the section .... in your application for a service that you technically don't know. Not the best approach.

The best approach is to move the service dependencies from DoWork.dll. You can do this by simply translating the logic into the UserService implementation.

Or, if you need to maintain DoWork.dll independence, consider moving DoWork with it to the WCF service, which depends on CompanyService. Then from the UserService add the service link to the new DoWork service. This is more consistent with SOA tenants and will allow your services to grow independently.

+3
source share

All Articles