이 꽤되지 않습니다 :
이 PowerShell 스크립트에서 이러한 방식의 예를 볼 수 있습니다. 이 코드를 부분적으로 사용자가 제공 한 링크에 기초한 다음 내부 요소와 해당 데이터 유형은 물론 스키마에 포함 된 여러 유형을 파싱하기 위해 재귀를 추가했습니다. 이것은 분명히 XML 스키마의 모든 가능성을 고려하지 않았지만, 필자는 필연적 인 경우이를 복잡하게 할 수 있다는 것을 충분히 예시 해 준다고 생각합니다.
이 도움이 되길 바랍니다. !!!!
internal class Program
{
private static void Main(string[] args)
{
//Build the URL request string
UriBuilder uriBuilder = new UriBuilder(@"http://digicomdev:8888/digitalOrderBroker/digitalOrderBroker.asmx");
uriBuilder.Query = "WSDL";
HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(uriBuilder.Uri);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Method = "GET";
webRequest.Accept = "text/xml";
//Submit a web request to get the web service's WSDL
ServiceDescription serviceDescription;
using (WebResponse response = webRequest.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
serviceDescription = ServiceDescription.Read(stream);
}
}
//Loop through the port types in the service description and list all of the
//web service's operations and each operations input/output
foreach (PortType portType in serviceDescription.PortTypes)
{
foreach (Operation operation in portType.Operations)
{
Console.Out.WriteLine(operation.Name);
foreach (var message in operation.Messages)
{
if (message is OperationInput)
Console.Out.WriteLine("Input Message: {0}", ((OperationInput) message).Message.Name);
if (message is OperationOutput)
Console.Out.WriteLine("Output Message: {0}", ((OperationOutput) message).Message.Name);
foreach (Message messagePart in serviceDescription.Messages)
{
if (messagePart.Name != ((OperationMessage) message).Message.Name) continue;
foreach (MessagePart part in messagePart.Parts)
{
Console.Out.WriteLine(part.Name);
}
}
}
Console.Out.WriteLine();
}
} //End listing of types
//Drill down into the WSDL's complex types to list out the individual schema elements
//and their data types
Types types = serviceDescription.Types;
XmlSchema xmlSchema = types.Schemas[0];
foreach (object item in xmlSchema.Items)
{
XmlSchemaElement schemaElement = item as XmlSchemaElement;
XmlSchemaComplexType complexType = item as XmlSchemaComplexType;
if (schemaElement != null)
{
Console.Out.WriteLine("Schema Element: {0}", schemaElement.Name);
XmlSchemaType schemaType = schemaElement.SchemaType;
XmlSchemaComplexType schemaComplexType = schemaType as XmlSchemaComplexType;
if (schemaComplexType != null)
{
XmlSchemaParticle particle = schemaComplexType.Particle;
XmlSchemaSequence sequence =
particle as XmlSchemaSequence;
if (sequence != null)
{
foreach (XmlSchemaElement childElement in sequence.Items)
{
Console.Out.WriteLine(" Element/Type: {0}:{1}", childElement.Name,
childElement.SchemaTypeName.Name);
}
}
}
}
else if (complexType != null)
{
Console.Out.WriteLine("Complex Type: {0}", complexType.Name);
OutputElements(complexType.Particle);
}
Console.Out.WriteLine();
}
Console.Out.WriteLine();
Console.In.ReadLine();
}
private static void OutputElements(XmlSchemaParticle particle)
{
XmlSchemaSequence sequence = particle as XmlSchemaSequence;
XmlSchemaChoice choice = particle as XmlSchemaChoice;
XmlSchemaAll all = particle as XmlSchemaAll;
if (sequence != null)
{
Console.Out.WriteLine(" Sequence");
for (int i = 0; i < sequence.Items.Count; i++)
{
XmlSchemaElement childElement = sequence.Items[i] as XmlSchemaElement;
XmlSchemaSequence innerSequence = sequence.Items[i] as XmlSchemaSequence;
XmlSchemaChoice innerChoice = sequence.Items[i] as XmlSchemaChoice;
XmlSchemaAll innerAll = sequence.Items[i] as XmlSchemaAll;
if (childElement != null)
{
Console.Out.WriteLine(" Element/Type: {0}:{1}", childElement.Name,
childElement.SchemaTypeName.Name);
}
else OutputElements(sequence.Items[i] as XmlSchemaParticle);
}
}
else if (choice != null)
{
Console.Out.WriteLine(" Choice");
for (int i = 0; i < choice.Items.Count; i++)
{
XmlSchemaElement childElement = choice.Items[i] as XmlSchemaElement;
XmlSchemaSequence innerSequence = choice.Items[i] as XmlSchemaSequence;
XmlSchemaChoice innerChoice = choice.Items[i] as XmlSchemaChoice;
XmlSchemaAll innerAll = choice.Items[i] as XmlSchemaAll;
if (childElement != null)
{
Console.Out.WriteLine(" Element/Type: {0}:{1}", childElement.Name,
childElement.SchemaTypeName.Name);
}
else OutputElements(choice.Items[i] as XmlSchemaParticle);
}
Console.Out.WriteLine();
}
else if (all != null)
{
Console.Out.WriteLine(" All");
for (int i = 0; i < all.Items.Count; i++)
{
XmlSchemaElement childElement = all.Items[i] as XmlSchemaElement;
XmlSchemaSequence innerSequence = all.Items[i] as XmlSchemaSequence;
XmlSchemaChoice innerChoice = all.Items[i] as XmlSchemaChoice;
XmlSchemaAll innerAll = all.Items[i] as XmlSchemaAll;
if (childElement != null)
{
Console.Out.WriteLine(" Element/Type: {0}:{1}", childElement.Name,
childElement.SchemaTypeName.Name);
}
else OutputElements(all.Items[i] as XmlSchemaParticle);
}
Console.Out.WriteLine();
}
}
}
martin, 귀하의 코드를 시도했지만 XmlSchema xmlSchema = types.Schemas [0]; 항상 null입니다. –
@ user465876 : 귀하의 URL이 WSDL을 올바르게 가리키고 있지 않습니다. 희망이 도움이됩니다! – pmartin
어떻게 확인할 수 있습니까? "? wsdl"을 사용하여 서비스 URL을 열면 잘 열립니다. 또한 게시 된 원래 예제를 사용하여 내 wsdl 구문 분석 된 및 모든 간단한 데이터 형식 있어요. 내가 놓칠지도 모르는 다른 것? –