当我尝试将restful wcf服务的引用添加到windows服务时。我收到“找不到类型或命名空间名称'RestfulService'(您是否缺少 using 指令或程序集引用?)”错误。
我的界面是
[ServiceContract(Name = "RJContract",
Namespace = "RestfulService",
SessionMode = SessionMode.Allowed)]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "/rjdata/{name}")]
string RJData(string name);
}
应用程序配置
<system.serviceModel>
<services>
<service name="RestfulService.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8732/RestfulService/Service1/" />
</baseAddresses>
</host>
<endpoint binding="webHttpBinding" contract="RestfulService.IService1" bindingConfiguration="RESTBindingConfiguration"
behaviorConfiguration="RESTEndpointBehavior"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="RESTBindingConfiguration">
<security mode="None" />
</binding>
</webHttpBinding>
<netTcpBinding>
<binding name="DefaultBinding">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="RESTEndpointBehavior">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
但我可以使用以下内容添加参考。
[ServiceContract(Name = "RJContract",
Namespace = "RestfulService",
SessionMode = SessionMode.Allowed)]
public interface IService1
{
[OperationContract]
string RJData(string name);
}
在 Windows 主机中
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
ServiceHost sHost;
protected override void OnStart(string[] args)
{
try
{
sHost = new ServiceHost(typeof(RestfulService.Service1));
sHost.Open();
}
catch (Exception ex)
{
EventLog.WriteEntry(ex.Message);
}
}
protected override void OnStop()
{
}
}
其中 RestfulService 是我对 wcf 服务的引用