简体   繁体   English

从Web表单调用时出现Web服务错误

[英]Web service error when invoked from web form

I have a program that utilize a web service. 我有一个利用Web服务的程序。 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: 当单独测试该Web服务(在AS .asmx上运行)运行良好时,但是尝试从Web表单内部进行调用时,会产生以下错误:

Client found response content type of 'text/html; 客户发现响应内容类型为'text / html; charset=utf-8', but expected 'text/xml'. charset = utf-8”,但预期为“ text / xml”。

The web servce is: Web服务是:

    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: 从中调用的Web表单是:

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服务旨在用作数据接口,而不是网页服务器,这就是为什么需要XML的原因。 Web service protocols use XML format for their communications, eg WSDL or SOAP. Web服务协议使用XML格式进行通信,例如WSDL或SOAP。 The .aspx page you attempt to transfer the processing to will return HTML. 您尝试将处理转移到的.aspx页面将返回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. 可能是因为当您在浏览器中尝试过该浏览器时,该浏览器已足够让您以您想要的方式来解释来自Web服务的答复,即使这并非本意。

A better thing to practise with would be something simple like adding two numbers. 更好的做法是将两个数字相加,这很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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