★★★ 大侠们救命!!!客户端 和 WCF 服务器端 在一台机器上,客户端 和 服务器端 可以正常进行数据交流,分到俩台机器上就不行,为什么?WCF 服务器端用的是ServiceHost启动.相关代码如下???? ★★★

abcdefu520 2008-01-11 05:36:46
客户端 和 服务器端 在一台机器上,客户端 和 服务器端 可以正常进行数据交流,分到俩台机器上就不行,为什么?WCF 服务器端用的是ServiceHost启动.

启动代码如下:

host.cs:
public static void Main( )
{
Uri baseAddress = new Uri("http://localhost:8000/WCF/MyService");
ServiceHost host = new ServiceHost(typeof(MyService), baseAddress);

WfWcfExtension wfWcfExtension = new WfWcfExtension("WorkflowRuntimeConfig");
host.Extensions.Add(wfWcfExtension);
host.Open();

Console.WriteLine("WCF service is ready.");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();

host.Close();
}

App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="WorkflowRuntimeConfig" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<system.serviceModel>
<services>
<service name="WCF.MyService" behaviorConfiguration="WCF.Service1Behavior">
<endpoint address ="http://localhost:8000/WCF/MyService" binding="wsHttpBinding" contract="WCF.IMyService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCF.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>


MyService.cs:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class MyService : IMyService
{
}


IMyService.cs:
[ServiceContract()]
public interface IMyService
{
[OperationContract]
string GetSearchInfo();
}

...全文
383 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
zeroes2021 2010-01-23
  • 打赏
  • 举报
回复
在防火墙上添加例外端口吧
gesheng_hd 2009-11-20
  • 打赏
  • 举报
回复
这个骗子,得分回复需要阅读,请登录CSDN!登录了还是一样,
zhujiechang 2008-03-06
  • 打赏
  • 举报
回复
让防火墙允许你的程序通过8080端口就可以了。
设置防火墙是必然的,除非你走80端口,那80端口默认是开放的,但就要把wcf放在iis里面去了。
kingxiekang 2008-03-05
  • 打赏
  • 举报
回复
帮顶 我也遇到了这个问题 提示Channel不可以 在本机没问题;;关注中
kingxiekang 2008-03-05
  • 打赏
  • 举报
回复
gyc 2008-03-05
  • 打赏
  • 举报
回复
如果关闭防火墙好事,
那就防火墙问题了,比如简单的个人防火墙在访问网络的之后会提示是否允许,企业的话一般是端口

闲话说道这里,

楼主服务器端使用代码初始化服务器实例

Uri baseAddress = new Uri("http://localhost:8000/WCF/MyService");
ServiceHost host = new ServiceHost(typeof(MyService), baseAddress);

地址可能被固定了,(这个并不主要)
在客户端生成服务代理的时候,会把这个地址记录元素据中,这样你需要把客户端的配置文件改成服务器的IP,才可以

TNT_1st_excellence 2008-03-05
  • 打赏
  • 举报
回复
localhost->另一台机子的ip地址
abcdefu520 2008-02-28
  • 打赏
  • 举报
回复
ding
abcdefu520 2008-02-27
  • 打赏
  • 举报
回复
ding
abcdefu520 2008-02-26
  • 打赏
  • 举报
回复
<binding>
<security mode="None" />
</binding>

加了.这个..但还是不行,,,,再顶...
abcdefu520 2008-02-26
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="WorkflowRuntimeConfig" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="myHttpBinding">
<security mode="None"/>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WCF.MyService" behaviorConfiguration="WCF.Service1Behavior">
<endpoint address ="http://192.168.9.127:8000/WCF/MyService"
binding="wsHttpBinding" bindingConfiguration="myHttpBinding"
contract="WCF.IMyService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCF.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>


<security mode="None"/>

改了.通不过

关掉防火墙就可以了..但这不是正确的作法吧.
gyc 2008-01-22
  • 打赏
  • 举报
回复
分开后报什么错误?
富莱工作室 2008-01-21
  • 打赏
  • 举报
回复
试试
<binding>
<security mode="None" />
</binding>
abcdefu520 2008-01-18
  • 打赏
  • 举报
回复
在网上有人说.防火墙,会堵塞8000端口,, 是这样的吗???

那我把,Uri 改为 http://localhost:8080/WCF/MyService

防火墙也会堵塞8080端口????????
abcdefu520 2008-01-17
  • 打赏
  • 举报
回复
不行,,


因为 host,cs和app.config是放在服务器端,所以尝试着,将下列俩行中的 localhost 分别改成服务器端的IP地址:
192.168.9.127

host.cs:
Uri baseAddress = new Uri("http://localhost:8000/WCF/MyService");
改:Uri baseAddress = new Uri("http://192.168.9.127 :8000/WCF/MyService");

App.config
<endpoint address ="http://localhost:8000/WCF/MyService" binding="wsHttpBinding"
改:<endpoint address ="http://192.168.9.127 :8000/WCF/MyService" binding="wsHttpBinding"

然后,在 客户端 程序中的,service参照 添加地址改为 http://192.168.9.127 :8000/WCF/MyService


可还是不行,是不是跟什么安全有关,,再求,,,,,,,,,,,
cloudgamer 2008-01-15
  • 打赏
  • 举报
回复
http://localhost:8000/WCF/MyService

用ip看看
nuistbaker 2008-01-12
  • 打赏
  • 举报
回复
顶下混点分呵呵
VirtualDesktop 2008-01-11
  • 打赏
  • 举报
回复
怎么又是这个问题

你的客户端配置文件里面服务的地址改了没有?要改成另外那台机器的 IP 不是 localhost

17,740

社区成员

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

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