Tôi nhận được lỗi "trạng thái bị lỗi" khi làm việc với Dịch vụ cốt lõi trong Phiên bản SDL 2011 SP1. Có vấn đề gì sau đây?Lỗi trạng thái bị lỗi khi tạo thành phần với Dịch vụ chính
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);
}
}
}
}
“tại System.ServiceModel.Channels.CommunicationObject.Close (TimeSpan timeout) tại System.ServiceModel.Channels.ServiceChannelFactory.OnClose (TimeSpan timeout) tại System.ServiceModel.Channels.ServiceChannelFactory.TypedServiceChannelFactory`1 .OnClose (TimeSpan timeout) tại System.ServiceModel.Channels.CommunicationObject.Close (TimeSpan timeout) tại System.ServiceModel.ChannelFactory.OnĐóng (TimeSpan timeout) tại System.ServiceModel.Channels.CommunicationObject.Close (TimeSpan timeout) tại System.ServiceModel .ChannelFactory.System.IDisposable.Dispose() tại coreservice1._Default.Page_Load (Đối tượng người gửi, EventArgs e) trong D: \ SampleProjects_Tridion \ test \ coreservice1 \ coreservice1 \ coreservice.aspx.cs: dòng 73exception là Giao tiếp Không thể sử dụng đối tượng, System.ServiceModel.Channels.ServiceChannel để liên lạc vì nó ở trạng thái Lỗi. ”
"Các đối tượng giao tiếp, System.ServiceModel.Channels.ServiceChannel, không thể được sử dụng để liên lạc vì nó là trong tình trạng đứt gãy." Điều này có nghĩa là đã xảy ra lỗi khi thực thi mã của bạn và bạn đã không xử lý mã đó đúng cách. Bạn có thể chia sẻ mã bạn đã sử dụng không? Cũng đáng xem bài đăng này từ Peter: http://pkjaer.wordpress.com/2011/11/30/core-service-clients-and-the-using-statement/ –
@NunoLinhares. Tôi đã cập nhật mã. Plz đã hiểu nó. – Patan
Mã này khá hữu ích. Bạn có thể vui lòng chỉ ra dòng nào là # 73? Thông báo lỗi trỏ tới dòng 73, nhưng tôi không thể ánh xạ nó trở lại đoạn mã này. –