开发者

C# + Programming against a web service with just .xsd and .xml files

I have an old school ASP (note: not ASP.NET) web site that has a file called "listener.asp". This fi开发者_运维技巧le is the interface to the "web service api". This file is on a machine that I cannot access for a while due to maintenance and implementation. However, I have been given a bunch of xml files. These xml files end with "*Request.xml" and "*Response.xsd".

My question is, can I implement my code to interact with through these .xml and .xsd files without needed to hit listener.asp? I know that I will not get any real data. But I thought there may be a way to build my app until the machine is available. Is there any way to do this?

I guess I'm assuming there is a reason for these .xml and .xsd files. I think that reason is to "define" the request and response objects. But I would like to figure out a way to code and test without having to rely on that machine. Is this possible with what I've been given?

Thank you


The best way would be to define an abstract class that provides access to your "web service api". Then create two derived classes, one that works with the real web service and one that retrieves fake responses from the files.

abstract class LegacyWebService
{
    public abstract int Foo();
}

class RealLegacyWebService : LegacyWebService
{
    public override int Foo()
    {
        return (int)XDocument.Load("http://www.example.com/foo").Root;
    }
}

class FakeLegacyWebService : LegacyWebService
{
    public override int Foo()
    {
        return (int)XDocument.Load(@"C:\Users\Me\Desktop\foo.xml").Root;
    }
}

You should also be able to create C# classes from your xsd files and use XML serialization to convert the XML responses from the web service or the file to C# objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜