如何使用C#API在AmazonMTurk上创建新的QualificationType?

如何使用C#API在AmazonMTurk上创建新的QualificationType?,c#,amazon-web-services,mechanicalturk,C#,Amazon Web Services,Mechanicalturk,我正在尝试创建一个新的资格类型,员工必须回答一个问题才能获得资格。下面是我的C代码。在C#api中使用createQualificationType方法时出错。请帮忙 using System; using System.Collections.Generic; using System.Text; using Amazon.WebServices.MechanicalTurk; using Amazon.WebServices.MechanicalTurk.Domain; namespace

我正在尝试创建一个新的资格类型,员工必须回答一个问题才能获得资格。下面是我的C代码。在C#api中使用createQualificationType方法时出错。请帮忙

using System;
using System.Collections.Generic;
using System.Text;
using Amazon.WebServices.MechanicalTurk;
using Amazon.WebServices.MechanicalTurk.Domain;

namespace CreateHITExample
{
    class Program
    {
        static SimpleClient client = new SimpleClient();

        static void Main(string[] args)
        {
            CreateNewHIT();
        }

        static void CreateNewHIT()
        {
            **QuestionFormQuestion** question = new QuestionFormQuestion();
            question.IsRequired = true;
            question.QuestionIdentifier = "1";
            **ContentType qnContent = new ContentType();**

            QualificationType qualType = client.CreateQualificationType("MyQual2", string.Empty, "My Qualification Type", QualificationTypeStatus.Active, 0, **question**, "680", 600, true, 100);
            string qualTypeId = qualType.QualificationTypeId;
            Console.WriteLine("Created Qualification Type ID 2: {0}", qualTypeId);
        }
    }
}
我必须将问题对象作为参数传递给CreateQualificationType方法。 从上面的代码中可以看到,question对象属于QuestionFormQuestion类

下面是一些可能会有所帮助的类定义

来自AWS MTurk dotnet API的QuestionFormQuestion类定义:

public class QuestionFormQuestion
    {
        public QuestionFormQuestion();

        public AnswerSpecificationType AnswerSpecification { get; set; }
        public string DisplayName { get; set; }
        public bool IsRequired { get; set; }
        [XmlIgnore]
        public bool IsRequiredSpecified { get; set; }
        **public ContentType QuestionContent { get; set; }**
        public string QuestionIdentifier { get; set; }
    }
public class ContentType
    {
        public ContentType();

        [XmlChoiceIdentifier("ItemsElementName")]
        [XmlElement("Application", typeof(ApplicationContentType))]
        [XmlElement("Binary", typeof(BinaryContentType))]
        [XmlElement("FormattedContent", typeof(String))]
        [XmlElement("Text", typeof(String))]
        [XmlElement("Title", typeof(String))]
        public object[] Items { get; set; }
        [XmlElement("ItemsElementName")]
        [XmlIgnore]
        public ItemsChoiceType[] ItemsElementName { get; set; }
    }
实际问题文本进入QuestionContent属性,该属性的类型为“ContentType”

来自AWS MTurk dotnet API的ContentType类定义:

public class QuestionFormQuestion
    {
        public QuestionFormQuestion();

        public AnswerSpecificationType AnswerSpecification { get; set; }
        public string DisplayName { get; set; }
        public bool IsRequired { get; set; }
        [XmlIgnore]
        public bool IsRequiredSpecified { get; set; }
        **public ContentType QuestionContent { get; set; }**
        public string QuestionIdentifier { get; set; }
    }
public class ContentType
    {
        public ContentType();

        [XmlChoiceIdentifier("ItemsElementName")]
        [XmlElement("Application", typeof(ApplicationContentType))]
        [XmlElement("Binary", typeof(BinaryContentType))]
        [XmlElement("FormattedContent", typeof(String))]
        [XmlElement("Text", typeof(String))]
        [XmlElement("Title", typeof(String))]
        public object[] Items { get; set; }
        [XmlElement("ItemsElementName")]
        [XmlIgnore]
        public ItemsChoiceType[] ItemsElementName { get; set; }
    }

我必须将实际的疑问句移动到ContentType对象的[XmlElement(“Text”,typeof(String))]元素。我不知道这样做的语法。请提供帮助。

我在使用Ruby SDK时遇到了相同的ValueException错误消息,直到我发现(与所有API文档示例不同,所有API文档示例都显示XML是预期的)CreateHit需要的是哈希,而不是某些参数的XML(例如XML表示疑问,但哈希表示限定要求)

在我的例子中,当我像文档中显示的那样提供XML时,它拒绝了资格要求,但当我将其作为散列提供时,它起了作用

但由于错误消息是相同的,我怀疑这可能也是您遇到的问题。(错误与语言无关……它不是来自SDK,而是SDK提交命中时从AWS返回的内容。)


未处理的异常:Amazon.WebServices.MechanicalTurk.Exceptions.InvalidParamet erValueException:值“[com.Amazon.MechanicalTurk.common.types.Qualificati”onTestDTO@d9899ed5]"对于参数测试无效。请继续,将所有信息编辑到您的问题中,使其格式正确且易于阅读。@Thomas如果更新的问题为您提供了足够的信息,请告诉我。非常感谢。