读书人

WCF#039;#039;#039;#039;#039;#039;俩台电脑,在后台手动启动一个

发布时间: 2012-01-24 23:11:54 作者: rapoo

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





[解决办法]
友情帮顶一下
[解决办法]
看看防火墙有没有阻塞8000端口
[解决办法]
至少你可以先把防火墙关了试一下,看是不是这个原因.
[解决办法]
刚解决了类似的问题
调整一下安全认证,最简单的把完全认证设为None,就可以通了


[解决办法]
Windows的防火墙,你不指明打开哪个端口,所有TCP入站端口和所有UDP端口都是被阻断的,包括HTTP的80端口。在防火墙中,为你需要的端口指定一个“例外”。
这是基本知识啊,尚需努力学习啊!

读书人网 >C#

热点推荐