我已将“ WCF服务应用程序”项目类型添加到我的VS解决方案(4.0)中。现在,出现的默认命名空间是“服务”,如果我运行应用程序(将WCF服务应用程序指向启动项目),它可以正常工作。
现在我已将名称空间更改为 XXX.YYY.Service.PartnerPortal ,如下
namespace XXX.YYY.Service.PartnerPortal
{
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
}
与IService1接口一样
namespace XXX.YYY.Service.PartnerPortal
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
}
此外,我还更改了项目属性中的默认命名空间
app.config文件在
下面<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
</compilation>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
</configuration>
在尝试运行时,我收到的错误消息是
错误:无法从http://localhost:65192/Service1.svc获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata上的MSDN文档.Exchange错误URI:http://localhost:65192/Service1.svc元数据包含无法解析的引用:'http:// localhost:65192 / Service1.svc'。服务器没有提供有意义的回复;这可能是由于合同不匹配,过早的会话关闭或内部服务器错误引起的.HTTP GET错误URI:http://localhost:65192/Service1.svc下载'http:// localhost:65192 / Service1.svc'时出错。请求失败并显示错误消息: - 类型为“Service.Service1”,在ServiceHost指令中作为Service属性值提供,或者在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations中提供。 body {font-family:“Verdana”; font-weight:normal; font-size:.7em; color:black;} p {font-family:“Verdana”; font-weight:normal; color:black; margin-顶部:-5px} b {font-family:“Verdana”; font-weight:bold;颜色:黑色; margin-top:-5px} H1 {font-family:“Verdana”; font-weight:normal; font-大小:18pt;颜色:红色} H2 {font-family:“Verdana”; font-weight:normal; font-size:14pt; color:maroon} pre {font-family:“Lucida Console”; font-size :. 9em} .marker {font-weight:bold; color:black; text-decoration:none;} .version {color:grey;} .error {margin-bottom:10px;} .expandable {text-decoration:underline;字体重量:粗体;颜色:海军;光标:手; }
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[InvalidOperationException: The type 'Service.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.] System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +51530 System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1461 System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +651[ServiceActivationException: The service '/Service1.svc' cannot be activated due to an exception during compilation. The exception message is: The type 'Service.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found..] System.Runtime.AsyncResult.End(IAsyncResult result) +688590 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +234 System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +359 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
我在做什么错,怎么解决?
答案 0 :(得分:5)
打开您的svc文件,并更正服务属性值
中的命名空间<%@ ServiceHost Language="C#" Debug="true" Service="XXX.YYY.Service.PartnerPortal.Service1" .....
答案 1 :(得分:0)
将配置文件更改为
<system.serviceModel>
<services>
<service behaviorConfiguration="Service.Service1Behavior" name="XXX.YYY.Service.PartnerPortal.Service1">
<endpoint address="" binding="wsHttpBinding" contract="XXX.YYY.Service.PartnerPortal.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Service.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>