4

我已将“ 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 Exchange 错误 URI:http://localhost:65192/Service1.svc的 MSDN 文档 元数据包含无法解析的引用:'http://localhost:65192/Service1.svc'。服务器没有提供有意义的回复;这可能是由于合同不匹配、会话过早关闭或内部服务器错误造成的。HTTP GET 错误 URI: http://localhost:65192/Service1.svc 下载“http://localhost:65192/Service1.svc”时出错。请求失败并显示错误消息:-- 类型“Service.Service1”,作为 ServiceHost 指令中的服务属性值提供,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。正文 {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-顶部:-5px} b {字体系列:“Verdana”;字体重量:粗体;颜色:黑色;边距顶部:-5px} H1 { 字体系列:“Verdana”;字体重量:正常;字体-大小:18pt;颜色:红色 } H2 { 字体系列:“Verdana”;字体重量:正常;字体大小:14pt;颜色:栗色 } pre {font-family:"Lucida Console";font-size: .9em} .marker {font-weight: bold; 颜色:黑色;文本装饰:无;} .version {颜色:灰色;} .error {margin-bottom:10px;} .expandable { 文本装饰:下划线;字体粗细:粗体;颜色:海军蓝;光标:手;}

“/”应用程序中的服务器错误。

找不到类型“Service.Service1”,作为 ServiceHost 指令中的服务属性值提供,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息: System.InvalidOperationException:类型“Service.Service1”,作为 ServiceHost 指令中的服务属性值提供,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。

源错误:

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

版本信息: ÿMicrosoft .NET Framework 版本:4.0.30319;ASP.NET 版本:4.0.30319.272 --.

我做错了什么以及如何解决?

4

2 回答 2

5

打开您的 svc 文件,并更正 Service 属性值中的命名空间

<%@ ServiceHost Language="C#" Debug="true" Service="XXX.YYY.Service.PartnerPortal.Service1" .....
于 2012-01-22T13:36:21.207 回答
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>
于 2012-01-22T07:21:40.517 回答