这是我的场景..。
我在VS2010中创建了一个BDC模型项目,以便在SharePoint2010中进行部署。我已经向我们在另一个系统上运行的WCF服务添加了一个服务引用。我希望我的ReadList方法调用另一个系统上的WCF服务来提取列表中显示的数据。
我已经为ReadList方法创建了一个单元测试,以在部署之前验证它是否有效。我得到的错误消息是“无法在ServiceModel客户端配置部分找到引用合同‘ServiceModel’的默认端点元素。”
当我添加服务引用时,会向项目中添加一个app.config,该项目似乎具备运行该服务所需的一切。
我的两个问题是
中吗?
发布于 2013-10-05 14:41:41
不幸的是,在本例中,我还没有找到使用app配置文件的方法。一种方法是在代码中定义端点,并可能将端点地址保存在农场属性包中。请注意,您必须添加对System.ServiceModel的引用。
private static string endpointUri = SPContext.Current.Site.WebApplication.Farm.Properties["Service_Uri_PropertyBag_Key"] as string;
private static EndpointAddress endpoint = new EndpointAddress(endpointUri);
private static BasicHttpBinding binding = new BasicHttpBinding();然后,调用WCF服务将类似于:
using (ReferencedServiceClient client = new ReferencedServiceClient(binding, endpoint))
{
return client.ReadList();
}发布于 2013-10-09 23:58:20
我在许多项目中使用过WCF与BDC一起工作。我通常做的事情如下所述。
1)创建一个单独的SharePoint解决方案,名为SPCommon
2)添加服务参考
3)创建MyAppSettings.cs
public class MyAppSettings
{
public string MyServiceEndPoint
{
get;
set;
}
}4)创建ConfigurationManager.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Configuration;
using System.Web.Configuration;
using Microsoft.SharePoint.Administration;
namespace MyApp
{
public class ConfigurationManager
{
SPSite site;
public ConfigurationManager(SPSite site)
{
this.site = site;
}
public MyAppSettings GetAppSettings()
{
try
{
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("/", site.WebApplication.Name);
AppSettingsSection appSettingSection = config.AppSettings;
MyAppSettings settings = new MyAppSettings();
settings.MyServiceEndPoint = appSettingSection.Settings["MyServiceEndPoint"].Value;
return settings;
}
catch (Exception ex)
{
// Log Error
}
return null;
}
}
}5)创建一个MyServiceConnection.cs文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyServiceReference;
using System.ServiceModel;
using Microsoft.SharePoint;
namespace MyApp
{
public class MyServiceConnection
{
public const int _maxBufferSize = 2147483647;
public const int _maxReceivedBufferSize = 2147483647;
public const int _maxStringContentLength = 2147483647;
public const int _maxArrayLength = 2147483647;
public const int _maxBytesPerRead = 2147483647;
public const int _maxNameTableCharCount = 2147483647;
public const int _maxDepth = 2147483647;
public static MyServiceProxyClient GetMyServiceProxyClient()
{
SPSite site = SPContext.Current.Site;
// Get the EndPointUrl from Web.config appsetting
ConfigurationManager configMgr = new ConfigurationManager(site);
var appSetting = configMgr.GetAppSettings();
EndpointAddress myServicecrmEndPoint;
if (appSetting != null)
{
myServiceEndPoint = new EndpointAddress(appSetting.MyServiceEndPoint);
var proxy = new MyServiceProxyClient(
new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly)
{
MaxBufferSize = _maxBufferSize,
MaxReceivedMessageSize = _maxReceivedBufferSize,
ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
{
MaxStringContentLength = _maxStringContentLength,
MaxArrayLength = _maxArrayLength,
MaxBytesPerRead = _maxBytesPerRead,
MaxNameTableCharCount = _maxNameTableCharCount,
MaxDepth = _maxDepth
},
},
myServiceEndPoint
);
return proxy;
}
else
{
// Log Error
return null;
}
}
}
}6)在外部列表解决方案中,添加对SPCommon项目的引用
7)调用服务方法ReadMyList(),如下所示
MyServiceProxyClient service = SPCommon.GetMyServiceProxyClient();
listData = service.ReadMyList();8)将追加添加到Web.config中
<appSettings>
<add key="MyServiceEndPoint" value="http://localhost:8101/MyService.svc" />
</appSettings>9)确保同时部署SPCommon和外部列表解决方案。
https://stackoverflow.com/questions/6259078
复制相似问题