简体   繁体   中英

Assembly reference missing in wcf service application

I am creating a Web application using WCF service.

Steps i followed is,

1) Created a new WCF Service Application.

2)Added a new WCF Service.

3) Created a Class Library.

4)Added a new class where i am having these codes mentioned below

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


namespace ClassLibrary1
{
    public interface IUSerDetails
    {
        [OperationContract]
        string InsertUserDetails(UserDetails user);
    }

    [DataContract]
    public class UserDetails
    {
        string username = string.Empty;
        string password = string.Empty;
        string country = string.Empty;
        string email = string.Empty;
        [DataMember]
        public string UserName
        {
            get { return username; }
            set { username = value; }
        }
        [DataMember]
        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        [DataMember]
        public string Country
        {
            get { return country; }
            set { country = value; }
        }
        [DataMember]
        public string Email
        {
            get { return email; }
            set { email = value; }
        }

    }
}

Now in Ln 13 when i do mousehover on [OperationContract] . It Gives an error. Are you missing a using directive or an assembly reference.

So i thought i missed the namespace

i added using system.ServiceModel; , but again its showing the same error in both the lines. What is missing out there?

as per link https://social.msdn.microsoft.com/Forums/vstudio/en-US/96ffb6d7-8737-4c4d-8512-58967d0b69cd/wcf-on-godaddy-compiler-doesnt-recognize-operationcontract?forum=wcf , you need to make two changes. First, add the following line to the httpmodules section of the web.config file:

<httpModules>



  <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>



</httpModules>

Second, add the following lines to the assemblies section of the web.config file:

  <assemblies>



    <add assembly="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>



    <add assembly="System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>



  </assemblies>

在“接口IUSerDetails”行上方写入[ServiceContract]

I was using Visual Studio for Mac to create a new Console project in .NET Framework 4.7.

Oddly it was quite happy with the [ServiceContract] attributes coming from System.ServiceModel but was complaining about the [OperationContract] attributes:

Program.cs(10,10): Error CS0246: The type or namespace name 'OperationContactAttribute' could not be found (are you missing a using directive or an assembly reference?) (CS0246)
Program.cs(10,10): Error CS0246: The type or namespace name 'OperationContact' could not be found (are you missing a using directive or an assembly reference?) (CS0246)

After checking the OperationContractAttribute Class documentation I discovered that the System.ServiceModel.Primitives assembly was required. For some reason the System.ServiceModel.Primitives assembly is not available in the Packages and .NET Assembly tabs via Project References.

I deleted all assemblies from Project References and fixed the above error with NuGet, ie:

Install-Package System.ServiceModel.Primitives

In addition to adding System.ServiceModel.Primitives to the Project References it also re-added:

  • mscorlib
  • System
  • System.IdentityModel
  • System.Runetime.Serialization
  • System.ServiceModel
  • System.Xml

Now I can re-add the other assemblies I need to continue. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM