The value is invalid according to its datatype 'clientcontracttype'

谁都会走 提交于 2020-01-12 02:32:13

问题


I am getting an error message saying:

The contract attribute is invalid. the value is invalid according to its datatype 'clientcontracttype'

Following is the endpoint configuration in web.config of this WCF application. I am using .NET Framework 4.5 and Visual Studio 2012. I have verified the contract OnlineReporting.Core.Contracts.IReportingInternalWcfPortal is already there.

<endpoint address="http://localhost:63817/ReportingInternalWcfPortal.svc" 
          binding="basicHttpBinding" 
          bindingConfiguration="BasicHttpBinding" 
          contract="OnlineReporting.Core.Contracts.IReportingInternalWcfPortal" 
          name="ReportingInternalPortal" />

回答1:


I see this question is pretty old and I don't know if you have found a solution by now, but just in case, this is what I have found will resolve:

1) In the Solution Explorer, under the Service References folder, right-click the service reference name with the issue and select 'Configure Service Reference'.

2) The Service Reference Settings window will appear. Uncheck the box labeled 'Reuse types in referenced assemblies' and click the OK button.

3) Rebuild the project.

After rebuilding, the warning should disappear.




回答2:


I found this question looking for the same error on a web service project.

In my case this error happened when I forgot to add the [ServiceContract] attribute on the IServiceBase interface.

As soon as I added it in the error went away.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace MyService
{
    [ServiceContract]
    public interface IServiceBase
    {
        [OperationContract]
        IEnumerable<ListItem> GetListItems();

        [OperationContract]
        void SaveListItems(IEnumerable<ListItem> listItems);
    }



回答3:


The same error occurs when you're missing a reference [in the project with the .config] to the actual project/library containing the interface/service contract...




回答4:


In my case I changed the Service Contract by unwittingly removing an interface which was key to the Service Contract.

Weeks later I found a broken client with an out of date service reference. Since the removal of the interface was in error I put it back in.

Another possible resolution would be to have rebuild the service reference to match the new service contract (in my case would have broken the project build since the referenced interface had been removed).

Thanks to OrangeKing89 for pointing me in the right direction. I knew there was the potential of the Service Contract being changed.




回答5:


In my case I had a naming conflict.

When you add a service reference, visual studio generates a client class as a proxy which implements the contract, the default name for that proxy is the name of the service appended by "Client" so if your service is "MyService" the client class would be "MyServiceClient".

My problem was that my project name was "MyServiceClient" ! which caused this conflict.




回答6:


I realize that this is an old thread, but in my case, the issue was that someone had at one time added a service reference to the project, and then decided to take another route, but the entry remained in web.config, so just deleting that entry in web.config solved the issue for me.




回答7:


I know that this question is ancient, however I ran into the same problem with C# and Visual Studio 2017. Everything was working and compiling fine, then it was not. I downgraded from .Net 4.6.2 to 4.6, as SQLite v108 does not support 108, then I received this error and others. It took me a bit of time to trace a solution. I did not see my solution anywhere, so I thought that I place it out there for the future.

I deleted my service reference, checked in all my changes to TFS, and then added back the service reference. I then built the solution and all was fine again.

I checked the app.config and other files and all seemed fine, just did not build. Obviously, VS2017 introduces .Net version information somewhere but not obviously.

Hopefully, my solution helps someone.




回答8:


If boths services are included in the same solution, you only have to perform two actions, providing that both services are working.

  • Add the reference to the project which contains the webserver you need. Do it from the "Projects" tab.
  • Configure your main service web.config like this:

    <services>
      <service name="MyCurrentProject.Service" behaviorConfiguration="ConfigRest">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="restServicehttp" name="RestEndpoint" bindingName="webHttpBinding" contract="MyCurrentProject.Service"/>
      </service>
      <service name="AnotherPoject.Service" behaviorConfiguration="ConfigRest">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="restServicehttp" name="RestEndpoint" bindingName="webHttpBinding" contract="AnotherPoject.Service"/>
      </service>
    




回答9:


In my case it was that the code was correct, the interface had the correct [ServiceContract] tag, and the .config endpoint had the correct interface namespace, but the project with the interface needed to be recompiled so that the other project that had the .config file would get an up to date .dll of the first project within its bin folder. So recompile the code is the answer to make visual studio happy.



来源:https://stackoverflow.com/questions/15497378/the-value-is-invalid-according-to-its-datatype-clientcontracttype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!