【发布时间】:2012-04-12 22:47:06
【问题描述】:
在 SDL Tridion 2011 SP1 中使用核心服务时出现“故障状态”错误。以下有什么问题?
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);
}
}
}
}
“在 System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout) 在 System.ServiceModel.Channels.ServiceChannelFactory.OnClose(TimeSpan timeout) 在 System.ServiceModel.Channels.ServiceChannelFactory.TypedServiceChannelFactory`1.OnClose(TimeSpan timeout)在 System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout) 在 System.ServiceModel.ChannelFactory.OnClose(TimeSpan timeout) 在 System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout) 在 System.ServiceModel.ChannelFactory.System.IDisposable .Dispose() at coreservice1._Default.Page_Load(Object sender, EventArgs e) in D:\SampleProjects_Tridion\test\coreservice1\coreservice1\coreservice.aspx.cs:line 73exception是通信对象,System.ServiceModel.Channels.ServiceChannel,无法用于通信,因为它处于故障状态。“
【问题讨论】:
-
"通信对象 System.ServiceModel.Channels.ServiceChannel 不能用于通信,因为它处于故障状态。"这意味着执行您的代码时出错并且您没有正确处理它。你能分享你使用的代码吗?也值得检查彼得的这篇文章:pkjaer.wordpress.com/2011/11/30/…
-
@NunoLinhares。我已经更新了代码。请看一下。
-
代码很有帮助。你能指出哪一行是#73吗?错误消息指向第 73 行,但我无法将其映射回此代码片段。
-
@Frank 问题不在第 73 行。问题在于匿名用户和 Windows 用户的身份验证。我为匿名用户和 Windows 用户启用了身份验证。然后错误就解决了。
标签: tridion