配置WCF服务并从一台机器访问另一台机器

时间:2015-01-07 00:34:20

标签: c# wcf

我正在尝试设置一个接受简单字符串值并返回字符串的WCF服务。我按照这里的教程 - > WCF Walkthrough但我试图做一个与示例不同的事情。我正在尝试从运行WcfServiceLibrary1的Windows 7的主机进行通信,并且我已经确认它正在使用WCF测试客户端并且我得到了回复 - 一切都很好。

我创建了一个Forms应用程序,如示例中所述,我通过从命令提示符执行netstat来引用我的主机的本地地址。返回192.168.1.104所以我将下面的链接插入我的Forms应用程序中的ServiceReference并找到了服务。

http://192.168.1.104:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/mex

我在Windows 7计算机上运行了WCF服务,然后在XP虚拟机上执行了Forms应用程序。根据示例,我通过按下下面的代码来调用服务调用。

private void btnSend_Click(object sender, EventArgs e)
{
    ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
    string response = client.GetData(txtData.Text);
    lblResponse.Text = response;
} 

我收到以下错误,我不确定如何解决这个问题。

  ERROR: There was no endpoint listening at http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.  INNER EXCEPTION: No connection could be made because the target machine actively refused it 127.0.0.1:8733    

对我来说奇怪的是为什么IP地址从我输入的值(从192开始)变为localhost。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

需要更新表单应用程序配置文件中服务引用元素的客户端部分。它看起来应该与此类似:

<client>
  <endpoint address="http://192.168.1.104:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/mex" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceLibrary1.Service1"
    name="BasicHttpBinding_IService1" />
</client>