【问题标题】:getting blank page in web service在 Web 服务中获取空白页面
【发布时间】:2016-05-10 09:02:53
【问题描述】:

我正在尝试了解 Web 服务和 wcf,但进展不顺利。我在 wcf 上遇到了同样的问题,所以我尝试了 webservice,但也得到了相同的页面。即使我使用 wcf 或 Web 服务示例视频制作完全相同的东西,我也会看到这个屏幕。我做错了什么,为什么会这样?当然,我该如何解决它?

我的 .asmx 类:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class HelloWebService : System.Web.Services.WebService
{

    [WebMethod]
    public string GetMessage(string name)
    {
        return "Hello " + name;
    }
}

我的 .aspx 页面:

<body>
<form id="form1" runat="server">
<table style="font-family:Arial">
    <tr>
        <td>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" OnClick="Button1_Click" runat="server" Text="Button" />
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label1" runat="server" Font-Bold="true" Text=""></asp:Label>
        </td>
    </tr>
</table>
</form>

还有我的代码隐藏:

protected void Button1_Click(object sender, EventArgs e)
    {
        HelloService.HelloWebServiceSoapClient client = 
            new HelloService.HelloWebServiceSoapClient();

        Label1.Text = client.GetMessage(TextBox1.Text);

    }

【问题讨论】:

  • 选择一种技术并学习它——不要在 ASMX(旧版和已弃用)和 WCF 之间跳跃,只需专注于 WCF。至于你看到的问题,你是如何到达那里的?你是从VS运行它吗?你在项目中设置了起始页吗?

标签: c# asp.net web-services wcf


【解决方案1】:

我在这里遗漏了一些东西。

您希望看到什么页面?您的 .aspx 页面?还是您的 .asmx 文件?如果是这样,您只需在 Visual Studio 中右键单击该文件并选择“设置为起始页”。

但通常,对于 WCF 服务,您应该有一个 .svc 文件,这应该是您的起点(但 WCF 服务并不意味着有一个“起始网页”) .

这是我从头开始创建 WCF Web 服务的分步教程的链接。

Creating WCF web services

这将向您展示如何创建 JSON Web 服务,然后您可以像这样调用它:

【讨论】:

    猜你喜欢
    • 2016-12-31
    • 1970-01-01
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    相关资源
    最近更新 更多