在SDL Tridion 2011 SP1中使用Core Service时出现"故障状态"错误.以下是什么问题?
namespace coreservice1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
using (ChannelFactory<ISessionAwareCoreService> factory =
new ChannelFactory<ISessionAwareCoreService>("wsHttp_2011"))
{
ISessionAwareCoreService client = factory.CreateChannel();
string SCHEMA_URI = "tcm:7-426-8";
var schemaFields = client.ReadSchemaFields(SCHEMA_URI, true, new ReadOptions());
foreach (var field in schemaFields.Fields)
{
Response.Write(string.Format("{0}", field.Name));
}
Response.Write(schemaFields.NamespaceUri);
string NEW_COMPONENT_FOLDER_URI = "tcm:8-15-2";
Tridion.ContentManager.CoreService.Client.ComponentData component = new Tridion.ContentManager.CoreService.Client.ComponentData
{
Schema = new LinkToSchemaData { IdRef = "tcm:8-426-8"},
Title = "Helloworldalll",
Id = "tcm:0-0-0",
LocationInfo = new LocationInfo
{
OrganizationalItem =
new LinkToOrganizationalItemData { IdRef = NEW_COMPONENT_FOLDER_URI}
},
};
string namespaceUri = schemaFields.NamespaceUri;
System.Text.StringBuilder content = new StringBuilder();
string First = "Hello World.This is Fisrt field";
content.AppendFormat("<{0} xmlns=\"{1}\">", schemaFields.RootElementName, namespaceUri);
content.AppendFormat("<{0} xmlns=\"{1}\">{2}</{0}>", "first", namespaceUri, First);
content.AppendFormat("</{0}>", schemaFields.RootElementName);
component.Content = content.ToString();
ComponentData comp = (ComponentData)client.Create(component, new ReadOptions());
string newlyCreatedComponentID = comp.Id;
Response.Write("Hello hai");
Response.Write("Id of newly created component: " + newlyCreatedComponentID);
}
}
catch (Exception ex)
{
Response.Write(ex.StackTrace);
Response.Write("exception is " + ex.Message);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
"System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)at System.ServiceModel.Channels.ServiceChannelFactory.OnClose(TimeSpan timeout)at System.ServiceModel.Channels.ServiceChannelFactory.TypedServiceChannelFactory`1.OnClose(TimeSpan timeout)at System. Service.ServiceModel.Channels.CommunicationObject.OnClose(TimeSpan timeout),位于System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)的System.ServiceModel.ChannelFactory.OnClose(TimeSpan timeout),位于System.ServiceModel.ChannelFactory.System.IDisposable.Dispose( )在coreservice1._Default.Page_Load(Object sender,EventArgs e)中的D:\ SampleProjects_Tridion\test\coreservice1\coreservice1\coreservice.aspx.cs:line 73exception是通讯对象,System.ServiceModel.Channels.ServiceChannel,不能使用为了沟通,因为它处于故障状态."
我认为这可能与您实例化客户端对象的方式有关.
您可以在Visual Studio中将其添加为服务引用:
例如,将服务引用添加到http:// {your tridion url} /webservices/CoreService.svc并为其指定TridionCoreService的命名空间,然后您可以像这样使用它:
TridionCoreService.CoreService2010Client client = new TridionCoreService.CoreService2010Client();
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用此处的方法,该方法允许您创建Core Service引用而无需配置文件.
| 归档时间: |
|
| 查看次数: |
1279 次 |
| 最近记录: |