[WCF]Web客户端调用WCF服务后,回调返回结果不显示,请大家帮帮忙

zhxingway 2010-06-11 11:39:09
大家好

我下载了微软的一个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);
}
}
}


请各位朋友帮我看看,怎样才能解决,谢谢.
...全文
895 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
nullnullcao 2012-11-22
  • 打赏
  • 举报
回复
亲,求帮助http://q.cnblogs.com/q/43786/
chinayy2012 2012-01-17
  • 打赏
  • 举报
回复
为什么 wcf项目中无法调用 using System.Web.UI.WebControls;
这句啊 求解
lxhdj2008 2010-09-09
  • 打赏
  • 举报
回复
来看看
理不完的逻辑 2010-06-17
  • 打赏
  • 举报
回复
友情帮顶!
zhxingway 2010-06-17
  • 打赏
  • 举报
回复
谢谢 Marguess 线下提供的思路.
我打算使用Ajax来解决这个问题.
zhxingway 2010-06-13
  • 打赏
  • 举报
回复
这是回调代码,问题还是一样,在调试中可以看到回调返回的值.但是不能在浏览器中显示,听说可以在代码中调用JS来更新控件的值,但是因为对这些数据的处理关系到绑定和图表,所以个人认为不太符合要求,如果只是单纯地显示出来,但可以调用JS来给窗体控件赋值.

public void Result(double result1)
{
this.TextBox1.Text += result1.ToString() + "\r\n";

}

public void Equation(string eqn)
{
this.TextBox1.Text += eqn + "\r\n";
}

熙风 2010-06-12
  • 打赏
  • 举报
回复
帮LZ顶顶
pc_242 2010-06-12
  • 打赏
  • 举报
回复
mark
zhxingway 2010-06-12
  • 打赏
  • 举报
回复
哎呀,我的MSN装了半个小时还没有装完.....


我是在微软网站下载的例子啊,不过全都显示是用VS2005来打开的.
是在.Net Framework3.0那部分下载的,
因为3.5的找不到例子下载,
谁能告诉我3.5的例子在哪里下载么???
JiuchunYoung 2010-06-12
  • 打赏
  • 举报
回复
帮你顶 呵呵 希望你 能够快点解决好这个问题哦 呵呵
zhxingway 2010-06-12
  • 打赏
  • 举报
回复
Marguess,我的确实是老代码哦,我参照你给的例子再看一下,有问题我再加你的MSN了,谢谢.
MarcuseXiao 2010-06-12
  • 打赏
  • 举报
回复
给你一个完整的配置,你只要扩展Services就行了
<!--WCF-->
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxEndpointBehaviors">
<enableWebScript />
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="AjaxServiceBehaviors">
<serviceMetadata httpsGetEnabled="false" httpGetEnabled="true" httpGetUrl=""/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="httpBinding">
<security mode="None">
</security>
</binding>
<!--下面的是为了https和http可以同时调用配置的,可以不要
<binding name="httpsBinding">
<security mode="Transport">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
</security>
</binding>-->
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
</serviceHostingEnvironment>
<services>
<service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="AjaxServiceBehaviors">
<endpoint address="" behaviorConfiguration="AjaxEndpointBehaviors" binding="webHttpBinding" bindingConfiguration="httpBinding" contract="Microsoft.ServiceModel.Samples.ICalculatorDuplex" />
<!--<endpoint address="" behaviorConfiguration="BLAjaxEndpointBehaviors" binding="webHttpBinding" bindingConfiguration="httpsBinding" contract="Microsoft.ServiceModel.Samples.ICalculatorDuplex" />-->
</service>
</services>
zfb312 2010-06-12
  • 打赏
  • 举报
回复
友情帮顶。
MarcuseXiao 2010-06-12
  • 打赏
  • 举报
回复
应该是Bind有问题,你这样试试:

<endpoint address="http://localhost/servicemodelsamples/service.svc"
binding="wsDualHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculatorDuplex" />
改成:
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="httpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculatorDuplex" />

在<Behaviors>同级增加
<bindings>
<webHttpBinding>
<binding name="httpBinding">
<security mode="None">
</security>
</binding>
</webHttpBinding>
</bindings>

ASP.NET不能用wsDualHttpBinding绑定
你下载的是老代码吧,在3.5 sp1下面的WCF与原来不同。别相信有些瞎写的书,例如 《...揭密》 那都是照着国外的文章翻译的,基本上没有验证的。
有问题你跟我联系MSN: marquessxiao@hotmail.com
zhxingway 2010-06-12
  • 打赏
  • 举报
回复

自己又顶一顶
zhxingway 2010-06-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wxr0323 的回复:]
我看了你的代码没看出什么问题!等高人来看看。
[/Quote]

代码运行和调试都没有问题哦,回调也有结果,但是就是在客户端显示不出来.
我现在觉得是回调操作控件有问题吧.
子夜__ 2010-06-12
  • 打赏
  • 举报
回复
我看了你的代码没看出什么问题!等高人来看看。
qiqishardgel 2010-06-12
  • 打赏
  • 举报
回复
友情帮顶!
zhxingway 2010-06-12
  • 打赏
  • 举报
回复

期待高手和热心人士出现.
zhxingway 2010-06-11
  • 打赏
  • 举报
回复
自己顶一顶
加载更多回复(3)

12,163

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧