日期:2014-05-18  浏览次数:21032 次

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,就可以通了