WCF SOAP服务:复杂类型属性为空

时间:2016-06-18 18:04:20

标签: c# web-services wcf soap xsd

我一直在尝试使用一段时间内提供的WSDL来设置WCF WebService,并且我感到非常沮丧,因为它无法正常工作。我构建的服务应该充当某种中间件,从客户端接收SOAP消息(使用SAP WSI / PI)并将消息内容推送到我们的CMS中。它似乎有点工作,但它无法获得复杂类型的值。

我会尝试尽可能完整,但由于我是一个非常温和的程序员,我可能会错过有价值的信息或使用错误的条款。如果您错过了一些帮助,请告诉我。我正在从我共享的模式中删除名称空间,试图隐藏我为其设置服务的客户。

我已收到客户提供的4个文件,我尝试用它来构建我的WebService。

  • 1 x Service.wsdl
  • 1 x Serivce.xsd
  • 2 x ExportXMLSchema.xsd

由于我唯一的问题是我在ExportXMLSchema.xsd中定义的复杂类型,我会分享这些内容。

ExportXMLSchema1.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://company.org/mail/hrm/JobPublication" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://company.org/mail/hrm/JobPublication" xmlns:p7="http://company.org/mail/global/datatypes">
    <xsd:import namespace="http://company.org/mail/global/datatypes" schemaLocation="file:///localfile/ExportXMLSchema2.xsd"/>
    <xsd:attributeGroup name="JobPositionPublication_Enhncmnt"/>
    <xsd:group name="JobPositionPublication_Enhncmnt">
        <xsd:sequence>
            <xsd:element name="ObjectSearchID" type="p7:JobPositionPostingID" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">767caf30a94311dfc60c00248143fb3c</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="PositionPlaceID" type="p7:JobPositionPostingID" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">767caf31a94311dfc92300248143fb3c</xsd:appinfo>
                    <xsd:documentation>Formatieplaats ID</xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="PositionPlaceDescription" type="p7:DescriptionHR" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">767caf32a94311df9bfa00248143fb3c</xsd:appinfo>
                    <xsd:documentation>Formatieplaats omschrijving</xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="City" type="p7:City" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">767caf33a94311df9f3900248143fb3c</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="PostalCodeFrom" type="p7:PostalCode" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">767caf34a94311dfa86b00248143fb3c</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="PostalCodeTo" type="p7:PostalCode" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">767caf35a94311dfb7f900248143fb3c</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="AreaDescription" type="p7:DescriptionHR" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">89c7af94b14111e19869984be172d7ee</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="TemporaryWorkerType" type="p7:TemporaryWorkerType" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">767caf37a94311dfa43d00248143fb3c</xsd:appinfo>
                    <xsd:documentation>THK</xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="PublicationFunctionID" type="p7:PublicationFunctionID" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">ca6011b0a94711dfbc1200248143fb3c</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="JobTitle" type="p7:DescriptionHR" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">c0807df0a94811dfc40e00248143fb3c</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="JobID" type="p7:JobPositionPostingID" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">c0807df1a94811df8d5000248143fb3c</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Availability" minOccurs="0" maxOccurs="unbounded" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">d48077a0a94911dfa0bc00248143fb3c</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="DayOfWeek" type="p7:DayOfWeek">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">e9bfdac0bc0411df9b5e18a9058b3aa3</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="DayPart" type="p7:DayPart">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">e9bfdac1bc0411dfbee818a9058b3aa3</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="TeamID" type="p7:TeamID" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">7a21a398b3c311e1c9ba78e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="TeamIDDescription" type="p7:DescriptionHR" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">7a21a399b3c311e1a1f678e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="AreaID" type="p7:AreaID" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">7a21a39ab3c311e1bf1478e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="AreaIDDescription" type="p7:DescriptionHR" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">4f871a83b3c911e1b30c78e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="Address" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">7a21a39db3c311e1bef978e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="Street" type="p7:StreetNameHR" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21a39bb3c311e187e278e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="City" type="p7:City" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21a39cb3c311e18f8e78e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="PostalCodeFrom" type="p7:PostalCode" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">943704b5b3c211e1c47678e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="PostalCodeTo" type="p7:PostalCode" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">943704b6b3c211e1b3f578e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="AreaDescription" type="p7:DescriptionHR" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">943704b7b3c211e186c378e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="WorkAgreementExtra" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">7a21a3a2b3c311e19c5178e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="HourPerDayMin" type="p7:Hours" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21a39eb3c311e1901e78e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="HourPerDayMax" type="p7:Hours" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21a39fb3c311e1927578e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="HourPerWeekMin" type="p7:Hours" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21a3a0b3c311e197c978e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="HourPerWeekMax" type="p7:Hours" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21a3a1b3c311e1c17078e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="Depot" minOccurs="0" maxOccurs="unbounded" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">7a21a3a6b3c311e1b8c278e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="DepotPostalCode" type="p7:PostalCode" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21a3a3b3c311e1a2f178e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="DepotStreet" type="p7:StreetNameHR" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21a3a4b3c311e1bf2478e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="DepotCity" type="p7:City" minOccurs="0">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21a3a5b3c311e19be578e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="AvailabilityOptional" minOccurs="0" maxOccurs="unbounded" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">7a21c3c9b3c311e1ce3b78e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="DayOfWeekOpt" type="p7:DayOfWeek">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21c3c7b3c311e18cea78e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                        <xsd:element name="DayPartOpt" type="p7:DayPart">
                            <xsd:annotation>
                                <xsd:appinfo source="http://sap.com/xi/TextID">7a21c3c8b3c311e1cc8478e3b50a88fe</xsd:appinfo>
                                <xsd:documentation/>
                            </xsd:annotation>
                        </xsd:element>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="AmountDayRequired" type="p7:Count" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">7a21c3cab3c311e1b2cb78e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="HomeDelivery" type="p7:Count" minOccurs="0" form="qualified">
                <xsd:annotation>
                    <xsd:appinfo source="http://sap.com/xi/TextID">7a21c3cbb3c311e1a63978e3b50a88fe</xsd:appinfo>
                    <xsd:documentation/>
                </xsd:annotation>
            </xsd:element>
        </xsd:sequence>
    </xsd:group>
</xsd:schema>

ExportXMLSchema2.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://company.org/mail/global/datatypes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://company.org/mail/global/datatypes">
    <xsd:simpleType name="LanguageCode">
        <xsd:restriction base="xsd:language">
            <xsd:minLength value="2"/>
            <xsd:maxLength value="9"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="DayPart.Content">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Part of the day</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="10"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="TeamID">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Generic object for Team IDs (Used for ERECRUIT)</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:maxLength value="8"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="DescriptionHR">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Generic description datatype used for HR objects</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="40"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="AreaID">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Generic object for Area IDs (Used for ERECRUIT)</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:maxLength value="8"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="StreetNameHR">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Generic Streetname datatype used for HR objects (40 pos.)</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="40"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="Count">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Generic object for Count (Used by ERECRUIT)</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:maxLength value="1"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="TemporaryWorkerType">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Temporary Worker (Tijdelijke hulpkracht (THK): N, K of J); TNT specific</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:maxLength value="1"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="JobPositionPostingID">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Generic object for JobPosting IDs (Used for ERECRUIT)</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:maxLength value="8"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="PostalCode">
        <xsd:restriction base="xsd:token">
            <xsd:minLength value="1"/>
            <xsd:maxLength value="10"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="Hours">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Generic datatype for hours</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:int">
            <xsd:maxInclusive value="2"/>
            <xsd:minInclusive value="1"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="PublicationFunctionID">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">PublicationFunctionID for ERECRUIT</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:maxLength value="3"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="City">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Cityname TNT</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/>
            <xsd:maxLength value="60"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:simpleType name="DayOfWeek.Content">
        <xsd:annotation>
            <xsd:documentation xml:lang="EN">Description day of the week</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:maxLength value="10"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:complexType name="DayPart">
        <xsd:simpleContent>
            <xsd:extension base="DayPart.Content">
                <xsd:attribute name="languageCode" type="LanguageCode"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>
    <xsd:complexType name="DayOfWeek">
        <xsd:simpleContent>
            <xsd:extension base="DayOfWeek.Content">
                <xsd:attribute name="languageCode" type="LanguageCode"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>
</xsd:schema>

我尝试了几种将服务引用导入项目的方法。将其添加为服务引用,并使用SVCUTIL创建类文件并将其导入到我的项目中(基本上通过覆盖原始服务引用)。当我设置我的服务并在本地或我们的开发服务器上托管它时,该服务工作正常。但是,我收到的消息(来自客户端或我自己使用SoapUI发送的消息)从不包含复杂类型属性。

示例消息包含可用性列表,如下所示:

<n0:Availability>
   <DayOfWeek>MAANDAG</DayOfWeek>
   <DayPart>OCHTEND</DayPart>
</n0:Availability>
<n0:Availability>
   <DayOfWeek>DINSDAG</DayOfWeek>
   <DayPart>OCHTEND</DayPart>
</n0:Availability>
<n0:Availability>
   <DayOfWeek>WOENSDAG</DayOfWeek>
   <DayPart>OCHTEND</DayPart>
</n0:Availability>

(n0匹配命名空间:http://company.org/mail/hrm/JobPublication

此消息在SoapUI中正确验证,但当我的服务收到消息时,DayOfWeek和DayPart的值为空。我确实收到三个&#34; Availbility&#34;价值观,所以部分有效。

我尝试使用/ ImportXmlTypes和/或/ Serializer:XmlSerializer等选项使用SVCUTIL生成类文件,但似乎没有任何效果。在这个板上发现的建议似乎都没有对我有用。希望有人可以指出我所忽视的内容。

提前致谢!

1 个答案:

答案 0 :(得分:0)

我发现我之前的一个解决方案毕竟是修复。

最有可能的解决方法是将schemaLocation属性添加到XSD和WSDL中的导入行。这是必要的,因为我提供此服务的公司改变了他们的公司名称,使命名空间无法访问。我的猜测是,在这种情况下,如果是这种情况,你需要添加对原始XSD的引用。我有一个本地副本,所以我指出了那个版本的XSD。这样,即使是复杂类型,Visual Studio也能够创建代理类。

我测试它的方式出了什么问题。每次我运行测试请求并进行调试时,我都在测试我的服务的旧版本,而不是我已经投入的更新。我猜错了新手,不幸的是我花了几个小时才意识到这一点。获得的经验:确保您有一个可靠的本地测试环境,您可以在其上正确调试。

请告诉我,如果我认为解决方案有问题,或者我还缺少其他任何内容。可能对我或遇到类似问题的其他人有帮助。