简体   繁体   中英

Web service error when invoked from web form

I have a program that utilize a web service. When this web service is tested on its own (run on ie AS .asmx) runs fine but when tried to be called from inside the web form it produces the following error:

Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'.

The web servce is:

    public Check1 () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public void check2(string destination) 
    {
        Server.Transfer(destination);   
    }
}

And the web form from which is called is:

protected void Button1_Click1(object sender, EventArgs e)
{
    localhost.Check1 new2 = new localhost.Check1();
    new2.check2("Ipal_apoth_page.aspx");
}

A web service is intended to be a data interface, not a web page server, which is why XML is expected. Web service protocols use XML format for their communications, eg WSDL or SOAP. The .aspx page you attempt to transfer the processing to will return HTML.

It may be that when you tried it in a browser, the browser was permissive enough to interpret the repsonse from the web service in the way you wanted even though that is not how it is meant to be used.

A better thing to practise with would be something simple like adding two numbers.

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