我正在为一个或多或少不受我控制的Web服务创建一个客户端.以下是架构的简化示例:
<xs:complexType name="A">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="element1" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="element2" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="B">
<xs:complexContent>
<xs:restriction base="A">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="element2" type="xs:string" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
简而言之,我们有一个包含所有元素的对象A. 该服务有几种基于A但有限制的类型,因此继承的类型通常小于基类型 - 这里以类型B为例.
在Visual Studio 2010,SoapUI等中的模式查看器中,这看起来像预期的那样.A有2个元素,B只有1个(=元素2).
通过使用svcutil我可以在我的类型A和B中获得完整的元素集,或者在使用选项时我会收到错误消息,例如:
错误:无法导入名称空间"http://tempuri.org/XMLSchema.xsd"中的"B"类型.不受支持派生的复杂类型.更改架构以便类型可以映射到数据协定类型或使用ImportXmlType或使用其他序列化程序.
隐藏继承类型中的字段/属性不是我喜欢旅行的练习/道路,但如果我无法让提供者更改WSDL,那么我似乎必须这样做.
有没有替代svcutil正确处理这个或我必须手工编码我的代理?
更新1
正如John Saunders所指出的,我没有展示svcutil的建议结果.这部分是为了保持这个职位的简短......但是这里有:
svcutil schema.xsd/importXmlTypes/datacontractonly导致:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="A", Namespace="http://tempuri.org/XMLSchema.xsd")]
public partial class A : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private string element1Field;
private string element2Field;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return …Run Code Online (Sandbox Code Playgroud) 我正在基于CRM系统中的动态对象在VS2010中生成实体包装器.除了实体代码之外,我还想添加一个EntityBase,所有实体都从中继承.如果该文件之前存在于该项目中,则不应添加该文件.我正在使用IWizard实现为生成器提供对象名称等.
是否可以在IWizard实现中确定是否添加项目(如果项目之前存在)?如何在ShouldAddProjectItem方法中或之前保留项目句柄及其项目?
到目前为止我的代码(未完成):
public class EntityWizardImplementation : IWizard
{
public void BeforeOpeningFile(ProjectItem projectItem)
{
//Note: Nothing here.
}
public void ProjectFinishedGenerating(Project project)
{
//Note: Nothing here.
}
public void ProjectItemFinishedGenerating(ProjectItem projectItem)
{
//Note: Nothing here.
}
public void RunFinished()
{
//Note: Nothing here.
}
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
try
{
var window = new WizardWindow();
// Replace parameters gathered from the wizard
replacementsDictionary.Add("$crmEntity$", window.CrmEntity);
replacementsDictionary.Add("$crmOrganization$", window.CrmOrganization);
replacementsDictionary.Add("$crmMetadataServiceUrl$", window.CrmMetadataUrl);
window.Close();
}
catch (SoapException …Run Code Online (Sandbox Code Playgroud)