以编程方式修改WSDL文件

时间:2018-04-10 12:56:49

标签: c# wsdl

我想自动修改Wsdl。目前我正在使用:

加载wsdl
string returnXML;

using (var client = new WebClient())
{
    var credential = new NetworkCredential(userName, securelyStroredPassword, domain);
    client.UseDefaultCredentials = true;
    client.Credentials = credential;

    returnXML = client.DownloadString(url+wsdl);
}
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(returnXML);

我未能对文档应用一些简单的规则:

将肥皂:地址位置值更改为url

    <wsdl:service name="foo">
        <wsdl:port name="foo" binding="tns:foo">
            <soap:address location="WrongLocation"/>
        </wsdl:port>
    </wsdl:service>

maxOccurs="unbounded"属性添加到xs:element

中的每个List<string> multipleOccurence
    .Where(x=> multipleOccurence.Contains(x.name) )

minOccurs="0"属性添加到具有属性xs:element的任何type="xs:string"

现在我无法选择一个简单的知道节点:

var aNode = xmlDoc.SelectNodes("/wsdl:definitions/wsdl:documentation/CreationInfo")

Wsdl的示例(无效,因为许多元素被截断以节省一些比特):

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions >

    <wsdl:types>

        <xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/Message" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/Message">
            <xs:complexType name="MessageBody">
                <xs:sequence>
                    <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>

        <xs:schema>
            <xs:element name="RequestFooBar">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="Header">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="DocumentID" type="xs:string"/>
                                    <xs:element name="AlternateDocumentID" type="xs:string"/>

                                    <xs:element name="Foos">
                                        <xs:complexType>
                                            <xs:sequence>
                                                <xs:element name="Foo">
                                                    <xs:complexType>
                                                        <xs:sequence>
                                                            <xs:element name="Type" type="xs:string"/>
                                                            <xs:element name="Foo" type="xs:string"/>
                                                        </xs:sequence>
                                                    </xs:complexType>
                                                </xs:element>
                                            </xs:sequence>
                                        </xs:complexType>
                                    </xs:element>

                                    <xs:element name="Bars">
                                        <xs:complexType>
                                            <xs:sequence>
                                                <xs:element name="Bar">
                                                    <xs:complexType>
                                                        <xs:sequence>
                                                            <xs:element name="Type" type="xs:string"/>
                                                            <xs:element name="Bar" type="xs:string"/>
                                                            <xs:element name="ExternalBar" type="xs:string"/>
                                                        </xs:sequence>
                                                    </xs:complexType>
                                                </xs:element>
                                            </xs:sequence>
                                        </xs:complexType>
                                    </xs:element>
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>         
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

            <xs:element name="ResponseFooBar">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="Ack">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="Code" type="xs:string"/>
                                    <xs:element name="Message" type="xs:string"/>
                                </xs:sequence>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

        </xs:schema>
    </wsdl:types>

    <wsdl:message name="FooBar_InputMessage">
        <wsdl:part name="part" element="tns:RequestFooBar"/>
    </wsdl:message>

    <wsdl:message name="Quotation_CreateQuotation_OutputMessage">
        <wsdl:part name="part" element="tns:ResponseFooBar"/>
    </wsdl:message>

    <wsdl:portType name="FOOFOO">
        <wsdl:documentation/>
        <wsdl:operation name="CreateQuotation">
            <wsdl:documentation/>
            <wsdl:input message="tns:FooBar_InputMessage"/>
            <wsdl:output message="tns:FooBar_OutputMessage"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:service name="foo">
        <wsdl:port name="foo" binding="tns:foo">
            <soap:address location="WrongLocation"/>
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

0 个答案:

没有答案