[英]Assembly reference missing in wcf service application
I am creating a Web application using WCF service. 我正在使用WCF服务创建Web应用程序。
Steps i followed is, 我遵循的步骤是
1) Created a new WCF Service Application.
1)创建一个新的WCF服务应用程序。
2)Added a new WCF Service.
2)添加了新的WCF服务。
3) Created a Class Library.
3)创建一个类库。
4)Added a new class where i am having these codes mentioned below
4)添加了一个新类,其中我有下面提到的这些代码
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]
. 现在在
Ln 13
当我在[OperationContract]
上进行鼠标悬停时。 It Gives an error. 它给出一个错误。 Are you missing a using directive or an assembly reference.
您是否缺少using指令或程序集引用。
So i thought i missed the namespace 所以我以为我错过了命名空间
i added using system.ServiceModel; 我使用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. 按照链接https://social.msdn.microsoft.com/Forums/vstudio/en-US/96ffb6d7-8737-4c4d-8512-58967d0b69cd/wcf-on-godaddy-compiler-doesnt-recognize-operationcontract?forum=wcf ,您需要进行两项更改。 First, add the following line to the httpmodules section of the web.config file:
首先,将以下行添加到web.config文件的httpmodules部分:
<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: 其次,将以下行添加到web.config文件的Assemblys部分:
<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. 我使用Visual Studio for Mac在.NET Framework 4.7中创建新的控制台项目。
Oddly it was quite happy with the [ServiceContract]
attributes coming from System.ServiceModel
but was complaining about the [OperationContract]
attributes: 奇怪的是,它对
System.ServiceModel
的[ServiceContract]
属性感到非常满意,但抱怨[OperationContract]
属性:
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. 在查看OperationContractAttribute类文档之后,我发现需要
System.ServiceModel.Primitives
程序集。 For some reason the System.ServiceModel.Primitives
assembly is not available in the Packages and .NET Assembly tabs via Project References. 由于某些原因,“项目”和“ .NET程序集”选项卡中的“
System.ServiceModel.Primitives
程序集无法通过“项目引用”获得。
I deleted all assemblies from Project References and fixed the above error with NuGet, ie: 我从“项目参考”中删除了所有程序集,并使用NuGet修复了上述错误,即:
Install-Package System.ServiceModel.Primitives
In addition to adding System.ServiceModel.Primitives
to the Project References it also re-added: 除了将
System.ServiceModel.Primitives
添加到项目引用之外,它还重新添加了:
Now I can re-add the other assemblies I need to continue. 现在,我可以重新添加需要继续的其他程序集。 Hope this helps.
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.