WCF''''''俩台电脑,在后台手动启动一个WCF HOST服务,前台的客户端用WEB参照,取不得数据;一台电脑做前台后台.可以取的.为什么.请教?

abcdefu520 2008-01-04 07:44:25
在后台手动启动一个WCF HOST服务,前台的客户端用WEB参照,取得数据;

问题: 后台跟前台在一台机器上时,数据可以得到.如果是同一局域网的俩台电脑,一台A(IP: 192.168.2.127)做为后台,一台B做为前台,取数据就不行,B机用IE流览http://192.168.2.127:8000/WCF/MyService 是可以看的到的.但数据取不到,为什么,代码如下

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>


启动HOST:

class Program
{
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.ReadKey();
Console.ReadLine();

host.Close();
}
}


MyService文件:

namespace WCF
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class MyService : IMyService
{
public string GetSearchDataData(string UserAccount, ref DataInfo getInfo)
{



}

:

:

}

}


IMyService文件:

namespace WCF
{
[ServiceContract()]
public interface IMyService
{

#region "Search"
[OperationContract]
string GetSearchDataData(string UserAccount, ref DataInfo getInfo);
:
:
:



...全文
303 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
sheepbo 2011-03-03
  • 打赏
  • 举报
回复
顶了 ~~!!!小弟也遇到了
kingxiekang 2008-03-05
  • 打赏
  • 举报
回复
帮顶 我也遇到这个问题在防火墙的例外中添加端口并且 <security mode="None"/> 后客户端还是看不到数据 关注中???!!
abcdefu520 2008-02-28
  • 打赏
  • 举报
回复
ding
abcdefu520 2008-02-27
  • 打赏
  • 举报
回复
ding
abcdefu520 2008-02-26
  • 打赏
  • 举报
回复
<binding>
<security mode="None" />
</binding>

加了.这个..但还是不行,,,,再顶...
horris 2008-02-26
  • 打赏
  • 举报
回复
Windows的防火墙,你不指明打开哪个端口,所有TCP入站端口和所有UDP端口都是被阻断的,包括HTTP的80端口。在防火墙中,为你需要的端口指定一个“例外”。
这是基本知识啊,尚需努力学习啊!
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"/>

改了.通不过

关掉防火墙就可以了..但这不是正确的作法吧.
hahahoo 2008-01-25
  • 打赏
  • 举报
回复
刚解决了类似的问题
调整一下安全认证,最简单的把完全认证设为None,就可以通了
possible_Y 2008-01-18
  • 打赏
  • 举报
回复
至少你可以先把防火墙关了试一下,看是不是这个原因.
abcdefu520 2008-01-18
  • 打赏
  • 举报
回复
在网上有人说.防火墙,会堵塞8000端口,, 是这样的吗???

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

防火墙也会堵塞8080端口????????
abcdefu520 2008-01-18
  • 打赏
  • 举报
回复
wt3056 2008-01-17
  • 打赏
  • 举报
回复
看看防火墙有没有阻塞8000端口
abcdefu520 2008-01-17
  • 打赏
  • 举报
回复
客户端 和 服务器端 在一台机器上,客户端 和 服务器端 (192.168.9.127) 可以正常进行数据交流,分到俩台机器上就不行,为什么?WCF 服务器端用的是ServiceHost启动.

启动代码如下:

host.cs:
public static void Main( )
{
Uri baseAddress = new Uri("http://192.168.9.127: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://192.168.9.127: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();
}
wsj1983920 2008-01-11
  • 打赏
  • 举报
回复
友情帮顶一下

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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