0

I have the following xml for Soap Message request. This below XML is to send Soap request to server. I like to generate source code to use in my .Net application to send request to server.

<s:Envelope
  xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SendMessage
      xmlns="http://www.localdomain.com/system/xsd/user-text-messaging/v3_1">
      <SendMessageRequest>
        <ClientIds>
          <ClientId>1900072003</ClientId>
          <ClientId>1900072004</ClientId>
          <ClientId>1900072005</ClientId>
        </ClientIds>
        <Message>Test message</Message>
        <DisplayDurationInSeconds>10</DisplayDurationInSeconds>
        <SequenceNumber>12</SequenceNumber>
      </SendMessageRequest>
    </SendMessage>
  </s:Body>
</s:Envelope>

I tried to use xsd.exe and generate C# source file but it hit errors as below.

C:\Users\zaung\source\repos\ComposingXxml\ComposingXxml>xsd SendMessage.xml
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'C:\Users\zaung\source\repos\ComposingXxml\ComposingXxml\SendMessage.xsd'.

C:\Users\zaung\source\repos\ComposingXxml\ComposingXxml>xsd SendMessage.xsd /c /order
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Schema validation warning: The 'http://www.localdomain.com/system/xsd/user-text-messaging/v3_1:SendMessage' element is not declared. Line 10, position 16.

Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.

Error: Error generating classes for schema 'SendMessage'.
  - The element 'http://www.localdomain.com/system/xsd/user-text-messaging/v3_1:SendMessage' is missing.

If you would like more help, please type "xsd /?".
CPMM
  • 76
  • 7
  • I don't know why it fails. But there might be a work-around. Try putting the XML in your clipboard. Then, in Visual Studio, choose Edit->Paste Special->Paste XML as classes. That'll create classes that match your XML. – Hans Kilian Feb 06 '18 at 09:59
  • I copied the xml provided to a file(SoapXml.xml) and generated xsd using visual studio. Visual studio generated 2 xsd files(SoapXml.xsd & SoapXml1.xsd. I don't know why ). Using xsd from command prompt I am able to generate a class for SoapXml1.xsd . Hope this helps. – JSR Feb 06 '18 at 11:53
  • Below link explains better https://stackoverflow.com/questions/1084071/why-does-xsd-exe-create-two-xsd-files-and-how-to-use-them. It seems I have use both xsd's to generate a class. – JSR Feb 06 '18 at 11:59

0 Answers0