WCF使用参考

时间:2013-09-09 19:23:31

标签: c# wcf wcf-binding

我已经创建了一个Windows服务,它的工作是在同一个项目中启动一个WCF服务。现在我在一个项目中有一个Windows客户端在同一个解决方案中。我已经成功地在客户端上添加了服务引用,但是当我在使用中键入服务引用时,如下所示,它无法识别。有谁知道这里发生了什么?我曾多次尝试过。我正在使用Visual Studio 2012.我在2010年之前成功使用过WCF(不是说那是问题)

客户代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Serv.......  //************ The reference is not recognized

namespace Validstate_Client
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {



        }
    }
}

客户端App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService2" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8733/Design_Time_Addresses/ValidStateService/Service2/"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService2"
                contract="ServiceReference2.IService2" name="BasicHttpBinding_IService2" />
        </client>
    </system.serviceModel>
</configuration>

1 个答案:

答案 0 :(得分:1)

该服务应该存在于Validstate_Client命名空间中。以下using语句应该有效:

using Validstate_Client.ServiceReference2