.net - 如何在更改 WCF 服务应用程序项目中的命名空间时运行 WCF 服务?

标签 .net wcf wcf-4

我已将“WCF 服务应用程序”项目类型添加到我的 VS 解决方案(4.0) 中。现在,显示的默认命名空间是“Service”,如果我运行该应用程序(将 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 接口(interface)

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 服务,请检查您是否已在指定地址启用元数据发布。如需启用元数据发布的帮助,请参阅 MSDN 文档:http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交换错误 URI:http://localhost:65192/Service1.svc元数据包含无法解析的引用:“http://localhost:65192/Service1.svc”。服务器没有提供有意义的回复;这可能是由契约(Contract)不匹配、 session 过早关闭或内部服务器错误引起的。HTTP GET 错误 URI:http://localhost:65192/Service1.svc下载“http://localhost:65192/Service1.svc”时出错。请求失败,并显示错误消息:-- 无法找到作为 ServiceHost 指令中的 Service 属性值提供的或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供的类型“Service.Service1”。 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:正常;font-大小:18pt;颜色:红色 } H2 { font-family:"Verdana";font-weight:正常;font-size:14pt;颜色:栗色 } pre {font-family:"Lucida Console";font-size: . 9em} .marker {字体粗细:粗体;颜色:黑色;文本装饰:无;} .version {颜色:灰色;} .error {margin-bottom:10px;} .expandable { 文本装饰:下划线;字体粗细:粗体;颜色:海军蓝;光标:手; }

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

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

描述:在执行当前的网络请求。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.InvalidOperationException:类型“Service.Service1”,作为 ServiceHost 指令中的 Service 属性值提供,或在配置元素 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.
堆栈跟踪:

<pre>[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</pre>
版本信息:ÿMicrosoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.272 --.

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

最佳答案

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

<%@ ServiceHost Language="C#" Debug="true" Service="XXX.YYY.Service.PartnerPortal.Service1" .....

关于.net - 如何在更改 WCF 服务应用程序项目中的命名空间时运行 WCF 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8959522/

相关文章:

.net - 从 IClientMessageInspector 获取请求 URI

c# - 从数据库中获取具有特定列的数据 MVC4

c# - 将值传递给 ObjectParameter 变量

.net - WCF内部队列监控(为了避免向服务发送太多请求)

iis - 如何使用基本身份验证将比用户名/密码更多的数据传递给 WCF 4.0 RESTful 服务中的服务方法

c# - WCF Post 请求内容类型 text/xml

c# - 如何自定义 ToolStripTextBox 的呈现?

.net - 如何规范化字符串?

c# - 单元测试 C# 属性

c# - 反射和 WCF