简体   繁体   English

WCF:无法找到端点引用

[英]WCF: Cannot find endpoint reference

I am working on a SharePoint 2013 webpart and a label on the webpart needs to communicate with a SQL Server data table using WCF. 我正在使用SharePoint 2013 webpart,并且webpart上的标签需要使用WCF与SQL Server数据表进行通信。 I have created the WCF interface and main class, and have also invoked the service in my Visual webpart like this: 我已经创建了WCF接口和主类,并且还在我的Visual webpart中调用了这样的服务,如下所示:

protected void Page_Load(object sender, EventArgs e)
    {
        WcfServiceReference1.Service1Client client = new WcfServiceReference1.Service1Client();
        CustomerNameLbl.Text = client.GetCustomerName(ProjectIDDescLbl.Text);
    }

Where WcfServiceReference1 is the added WCF service reference and a customer label text is being changed depending on the project number label. 其中WcfServiceReference1是添加的WCF服务引用,并且正在根据项目编号标签更改客户标签文本。 The project builds and deploys fine but when I add the webpart, I get this error: Could not find default endpoint element that references contract 'WcfServiceReference1.IService1' in the ServiceModel client configuration section. 该项目构建和部署正常,但是当我添加webpart时,我收到此错误: 找不到引用ServiceModel客户端配置部分中的合同'WcfServiceReference1.IService1'的默认端点元素。 This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element. 这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

My app.config file is this: 我的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>

And web.config file (for SharePoint) is this: 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>

Can anyone guide me on how to resolve this? 任何人都可以指导我如何解决这个问题? Am I going wrong somewhere? 我在某个地方出错了吗?

After a lot of research, I found out that there was some problem with SharePoint which I don't really understand. 经过大量的研究,我发现SharePoint存在一些我不太懂的问题。 Thankfully, in time, I chose not to go the SharePoint way and instead work with a simple .aspx page and that would resolve the issue. 值得庆幸的是,及时,我选择不使用SharePoint方式,而是使用简单的.aspx页面,这将解决问题。 Just unhappy with Microsoft not offering as much support on such common issues. 对于微软没有对这些常见问题提供尽可能多的支持感到不满。

I had the same problem and I found this link. 我有同样的问题,我找到了这个链接。

http://social.technet.microsoft.com/Forums/en-US/dea0763d-d6ea-4659-8ef0-8275514d066a/sp2010-consuming-web-service-in-visual-web-part?forum=sharepointdevelopmentprevious http://social.technet.microsoft.com/Forums/en-US/dea0763d-d6ea-4659-8ef0-8275514d066a/sp2010-consuming-web-service-in-visual-web-part?forum=sharepointdevelopmentprevious

I did it and worked fine. 我做到了,工作得很好。 The problem is the deploy does not copy the service model configuration from the Visual Studio' app.config to the IIS's web.config. 问题是部署不会将服务模型配置从Visual Studio的app.config复制到IIS的web.config。

I hope helps. 我希望有所帮助。

Best Regards. 最好的祝福。

Your client endpoint does not seem to have a default configuration (name="" or nameless). 您的客户端端点似乎没有默认配置(name =“”或无名称)。 Try using: 尝试使用:

WcfServiceReference1.Service1Client client = new WcfServiceReference1.Service1Client("BasicHttpBinding_IService1");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM