[WCF]Web客户端调用WCF服务后,回调返回结果不显示,请大家帮帮忙
大家好
我下载了微软的一个WCF示例,它用IIS承载WCF服务,采用双工回调技术,示例中客户端采用控制台应用程序.
我把客户端改成WebForm应用程序后,回调结果显示不出来,但是在调试的时候有时可以得到和显示正确结果.
下面我把Web客户端的前后台代码贴出来,另外提供整个源码下载.
http://www.zhstrong.com/uploadfiles/cs.rar
请各位朋友帮我看看,怎样才能解决,谢谢.
我下载了微软的一个WCF示例,它用IIS承载WCF服务,采用双工回调技术,示例中客户端采用控制台应用程序.
我把客户端改成WebForm应用程序后,回调结果显示不出来,但是在调试的时候有时可以得到和显示正确结果.
下面我把Web客户端的前后台代码贴出来,另外提供整个源码下载.
http://www.zhstrong.com/uploadfiles/cs.rar
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" Height="345px" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Button" />
<asp:Button ID="Button4" runat="server" onclick="Button4_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceModel;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page,WebClientTest.ICalculatorDuplexCallback
{
//WebClientTest为引用的WCF服务命名空间
WebClientTest.CalculatorDuplexClient client;
double value;
protected void Page_Load(object sender, EventArgs e)
{
InstanceContext instanceContext = new InstanceContext(this);
//每次执行Button事件,client都为空.
// Create a client
if (client == null)
{
//创建WCF服务的客户端
client = new WebClientTest.CalculatorDuplexClient(instanceContext);
}
}
#region ICalculatorDuplexCallback 成员
/// <summary>
/// 实现回调成员
/// </summary>
/// <param name="result1"></param>
public void Result(double result1)
{
this.TextBox1.Text += result1.ToString() + "\r\n";
}
public void Equation(string eqn)
{
this.TextBox1.Text += eqn + "\r\n";
}
#endregion
protected void Button1_Click(object sender, EventArgs e)
{
// Call the AddTo service operation.
//调用WCF服务
value = 100.00D;
client.AddTo(value);
}
protected void Button2_Click(object sender, EventArgs e)
{
// Call the SubtractFrom service operation.
value = 50.00D;
client.SubtractFrom(value);
}
protected void Button3_Click(object sender, EventArgs e)
{
// Call the MultiplyBy service operation.
value = 17.65D;
client.MultiplyBy(value);
}
protected void Button4_Click(object sender, EventArgs e)
{
// Call the DivideBy service operation.
value = 2.00D;
client.DivideBy(value);
}
}
}
请各位朋友帮我看看,怎样才能解决,谢谢.
...全文
相关推荐
WCF服务创建,并调用(调用过程,不需添加服务引用)
WCF服务创建,并调用(调用过程,不需添加服务引用)。 打破传统的添加服务引用的方式,直接通过地址调用。请求和返回结果以JSON的形式来添加
WCF在Web开发中的应用:网页调用服务案例
Windows Communication Foundation (WCF) 是一个用于构建分布式应用程序的框架,它在.NET环境中提供了多种通信模式的支持。WCF整合了多种技术和服务,包括Web服务、.NET Remoting、COM+、MSMQ等,实现了统一的编程模型和API接口。它允许开发者通过服务契约声明性地定义服务功能,从而可以轻松地创建、发布和调用网络服务。
C# WCF分布式应用实践:服务建立与客户端调用
服务合约是服务端与客户端之间通信的基础。通过合约,客户端知道可以调用哪些方法以及这些方法的输入和输出参数。服务合约通常包含如下信息:服务操作:定义客户端可以调用的方法。数据契约:定义传递给和从服务返回的数据类型。消息交换模式:定义客户端和服务端之间消息如何交换,典型的有请求/响应模式和单向消息模式。set;set;set;在上面的例子中,和类使用标记,表示它们可以作为消息的一部分发送。标记的属性则表示数据成员。
WCFService可以通过web调用和WCF服务访问
WCF服务,配置可同时支持web调用和WCF调用,可以用于C#程序服务访问,也支持java等程序访问。java通过web调用,C#可以通过wcf访问。
wcf,c#调用wcf 服务
wcf,c#调用wcf 服务,包括 服务器端,客服端 简单示例供参考


Web Services

