简体   繁体   中英

Using a alternate XML DTD with a ASP.NET Web Service Application

I'm new to the .NET framework (and actually consider myself more of a sysadmin) but am creating a web service that needs to return data to another system. I was using the defaults from the ASP.NET Web Service Application project. The problem that I am having is I can't find a setting to use an alternate DTD. So by default the project returns this when I return a simple object I get something like this

<?xml version="1.0" encoding="utf-8"?>
<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://foo.com">
  <foo1>1</foo1>
  <bar>2</bar>
  <baz>3</baz>
</foo> `

When what I really would like is something like this ...

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE ivr_info SYSTEM "http://www.mybz.com/xml/ivr.dtd">
<response>
    <result>
        <ivr_info>
            <variables>
                <variable>
                    <name>foo1</name>
                    <value>1</value>
                </variable>
                <variable>
                    <name>bar</name>
                    <value>2</value>
                </variable>
            </variables>
        </ivr_info>
    </result>
</response>

I have the DTD for the new format is there a way to import that into a web service or do I need to drop down to a more base level and just write out and parse the incoming streams? Thanks in advance for any information.

ASP.Net web services handle all the xml serialization internally, which is why you're seeing the standard representation you first listed.

You can control the serialization using WCF. However, it does involve coding at more base levels to generate the kind of output you're looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM