【问题标题】:Service Generated from WSDL Returns Different WSDL从 WSDL 生成的服务返回不同的 WSDL
【发布时间】:2009-07-31 09:25:59
【问题描述】:

我已经从交付的 WSDL 架构生成了一个 WCF 服务接口,然后这个接口已经在我的一个 WCF 服务中实现,没有任何问题。

[ServiceBehavior(Name = "HL7Service", Namespace = "urn:hl7-org:v3")]
[ServiceContract(Namespace = "urn:hl7-org:v3", Name = "HL7Service", SessionMode = SessionMode.Allowed)]
public class HL7Service : IPatientRegistryQueryTracker_Binding
{


    [OperationContract(IsTerminating = false, IsInitiating = true, IsOneWay = false, AsyncPattern = false, Action = "PRPA_IN201302NO_Operation")]
    public PRPA_IN201302NOResponse PRPA_IN201302NO_Operation(PRPA_IN201302NO request)
    {

    }

    [OperationContract(IsTerminating = false, IsInitiating = true, IsOneWay = false, AsyncPattern = false, Action = "PRPA_IN201304NO_Operation")]
    public PRPA_IN201304NOResponse PRPA_IN201304NO_Operation(PRPA_IN201304NO request)
    {

    }

}

奇怪的是,我的新服务中的 WSDL 不符合生成它的 WSDL?

交付的 WSDL 的一部分看起来如何的示例

    <xs:complexType name="PRPA_MT201302UV02.Patient">
    <xs:sequence>
        <xs:group ref="InfrastructureRootElements"/>
        <xs:element name="id" type="PRPA_MT201302UV02.Patient.id" maxOccurs="unbounded"/>
        <xs:element name="addr" type="AD" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="telecom" type="TEL" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="statusCode" type="PRPA_MT201302UV02.Patient.statusCode"/>
        <xs:element name="effectiveTime" type="IVL_TS" minOccurs="0"/>
        <xs:element name="confidentialityCode" type="CE" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="veryImportantPersonCode" type="CE" minOccurs="0"/>
        <xs:choice>
            <xs:element name="patientPerson" type="PRPA_MT201302UV02.Patient.patientPerson" nillable="true"/>
            <xs:element name="patientNonPersonLivingSubject" type="PRPA_MT201302UV02.Patient.patientNonPersonLivingSubject" nillable="true"/>
        </xs:choice>
        <xs:element name="providerOrganization" type="COCT_MT150003UV03.Organization" nillable="true" minOccurs="0"/>
        <xs:element name="subjectOf" type="PRPA_MT201302UV02.Subject4" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="coveredPartyOf" type="PRPA_MT201302UV02.CoveredParty" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attributeGroup ref="InfrastructureRootAttributes"/>
    <xs:attribute name="nullFlavor" type="NullFlavor" use="optional"/>
    <xs:attribute name="classCode" type="RoleClass" use="required" fixed="PAT"/>
</xs:complexType>

这是生成到我的服务的以下接口

    [System.Xml.Serialization.XmlElementAttribute("patientNonPersonLivingSubject", typeof(PRPA_MT201302UV02PatientpatientNonPersonLivingSubject), IsNullable=true)]
[System.Xml.Serialization.XmlElementAttribute("patientPerson", typeof(PRPA_MT201302UV02PatientpatientPerson), IsNullable=true)]
public object Item {
    get {
        return this.itemField;
    }
    set {
        this.itemField = value;
    }
}

这没问题。这就是我的服务 WSDL 中相同部分的外观。

<xs:complexType name="PRPA_MT201302UV02Patient">
−
<xs:sequence>
    <xs:element name="addrField" nillable="true" type="tns:ArrayOfAD"/>
    <xs:element name="classCodeField" nillable="true" type="xs:string"/>
    <xs:element name="confidentialityCodeField" nillable="true" type="tns:ArrayOfCE"/>
    <xs:element name="coveredPartyOfField" nillable="true" type="tns:ArrayOfPRPA_MT201302UV02CoveredParty"/>
    <xs:element name="effectiveTimeField" nillable="true" type="tns:IVL_TS"/>
    <xs:element name="idField" nillable="true" type="tns:ArrayOfPRPA_MT201302UV02Patientid"/>
    <xs:element name="itemField" nillable="true" type="xs:anyType"/>
    <xs:element name="nullFlavorField" nillable="true" type="xs:string"/>
    <xs:element name="providerOrganizationField" nillable="true" type="tns:COCT_MT150003UV03Organization"/>
    <xs:element name="realmCodeField" nillable="true" type="tns:ArrayOfCS"/>
    <xs:element name="statusCodeField" nillable="true" type="tns:PRPA_MT201302UV02PatientstatusCode"/>
    <xs:element name="subjectOfField" nillable="true" type="tns:ArrayOfPRPA_MT201302UV02Subject4"/>
    <xs:element name="telecomField" nillable="true" type="tns:ArrayOfTEL"/>
    <xs:element name="templateIdField" nillable="true" type="tns:ArrayOfII"/>
    <xs:element name="typeIdField" nillable="true" type="tns:II"/>
    <xs:element name="veryImportantPersonCodeField" nillable="true" type="tns:CE"/>
</xs:sequence>

choice 元素被替换为简单的 anyType 元素?问题在于客户端代理类中永远不会生成假定放置在 itemfield 上的类型(PRPA_MT201302UV02.Patient.patientPerson 和 PRPA_MT201302UV02.Patient.patientNonPersonLivingSubject)?

我已尝试从生成服务的 delivered WSDL 架构生成代理客户端类,这将创建一个正确的代理客户端,但在尝试与服务通信时会出现Datacontract 不匹配异常

为什么 WSDL 架构不一样?

【问题讨论】:

  • 为什么会是一样的?一个正在生成,另一个在文件中。如果您希望它相同,那么您应该让 WCF 从文件中返回 WSDL。
  • 如果 WCF 服务实现了一个从 MySchemaA.WSDL 生成的接口,那么我希望该服务遵循这个 WSDL 并因此呈现它自己的 WSDL 完全相同。如何让我的服务单独提供 MySchemaA.WSDL?这真的会吗?异常应该不一样吗?
  • 不,不应该。尤其如此,因为您的 WSDL 使用了对互操作性造成压力的复杂特性。例如 xs:group。

标签: c# wcf wsdl datacontract


【解决方案1】:

看起来您正在使用操作合同而不是合同(接口)来标记类。

此外,如果您使用 DataContract / DataMember 属性标记了您的消息,您也不会显示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-16
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    相关资源
    最近更新 更多