【发布时间】:2013-09-02 16:46:03
【问题描述】:
我正在处理 SharePoint 2013 webpart,并且 webpart 上的标签需要使用 WCF 与 SQL Server 数据表进行通信。我已经创建了 WCF 接口和主类,并且还在我的 Visual webpart 中调用了该服务,如下所示:
protected void Page_Load(object sender, EventArgs e)
{
WcfServiceReference1.Service1Client client = new WcfServiceReference1.Service1Client();
CustomerNameLbl.Text = client.GetCustomerName(ProjectIDDescLbl.Text);
}
其中 WcfServiceReference1 是添加的 WCF 服务引用,并且客户标签文本正在根据项目编号标签进行更改。项目构建和部署正常,但是当我添加 webpart 时,我收到此错误:在 ServiceModel 客户端配置部分中找不到引用合同“WcfServiceReference1.IService1”的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。
我的 app.config 文件是这样的:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://as-sv-dev02:2345/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
web.config 文件(用于 SharePoint)是这样的:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://as-sv-dev02:2345/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
谁能指导我如何解决这个问题?我是不是哪里出错了?
【问题讨论】:
-
您使用的是什么版本的 .NET?另外,为什么你的 app.config 中有一个客户端端点(我假设它是用于你的服务的)?
-
我正在使用 .NET 4.5(使用 Visual Studio 2012),并且在谷歌搜索很多之后我在那里有那个端点,但这是问题的原因吗?
-
不,只是不需要,除非该服务还调用另一个服务(在这种情况下充当客户端)。由于您使用的是 4.5,因此您将拥有服务的默认端点,该端点将是 Service1.svc 文件所在位置的地址。如果你在浏览器中访问
http://as-sv-dev02:2345/Service1.svc,你会看到什么? -
这个异常的原因是你的包含
的配置文件(app.config / web.config)没有被拾取。如果我正确理解您的问题,您的服务托管在其他地方,并且您的 Web 部件是您现在失败的 WCF 服务的客户端?您应该确保您的 webpart / WCF 客户端代码运行的任何位置都具有此配置。那应该可以解决您的问题。我看到你有两个配置文件?为什么是 2 个配置文件? -
@Praburaj - 其中一个配置是针对他们的 Sharepoint 应用程序;另一个是(我猜)服务本身。
标签: c# .net wcf sharepoint