gpt4 book ai didi

c# - WSCF.blue服务错误 "implementation type is an interface or abstract class and no implementation object was provided"生成的WCF服务

转载 作者:太空宇宙 更新时间:2023-11-03 16:19:43 25 4
gpt4 key购买 nike

我正在使用 C# Visual Studio 2012 创建一个 wcf 服务。

我让 WSC​​F.blue 工具从 xsd-s 生成 wsdl。然后我使用相同的工具生成了 Web 服务代码。 WSCF.blue 不创建服务契约和数据契约。它创建一个接口(interface)和一个包含实现该接口(interface)的类的 .svc 文件。

在生成 Web 服务代码时,我选择了创建抽象类的选项,因为我希望能够将这些类的实现保存在一个单独的文件中。

抽象类如下所示:

 [KnownType(typeof(WebMobileImplementation))]     
public abstract class WebMobile : IWebMobile
{
public abstract PutLocationsResponse PutLocations(PutLocationsRequest request);
}

实现类(在不同的文件中)看起来像这样(现在):

 public class WebMobileImplementation : WebMobile
{
public override PutLocationsResponse PutLocations(PutLocationsRequest request)
{
PutLocationsResponse response = new PutLocationsResponse();
return response;
}
}

尝试浏览服务时,我收到消息:“服务实现类型是接口(interface)或抽象类,未提供实现对象”我认为将已知类型添加到实现类中可以解决问题,但似乎在运行服务时“看不到”实现。我还能做些什么来“连接”他们?

最佳答案

在 WCF 4.0 中,您可以在 Web.config 中定义映射到您的服务类型的虚拟服务激活端点。这使得激活 WCF 服务成为可能,而无需维护物理 .svc 文件。

<serviceHostingEnvironment>
<serviceActivations>
<add relativeAddress="WebMobile.svc"
service="WebMobileNamespace.WebMobileImplementation"/>
</serviceActivations>
</serviceHostingEnvironment>

关于c# - WSCF.blue服务错误 "implementation type is an interface or abstract class and no implementation object was provided"生成的WCF服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14464585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com