创建代理类实例时出错

时间:2014-05-14 21:00:14

标签: web-services wcf rest asp.net-mvc-5 windows-forms-designer

这是错误:

The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.

当我尝试实例化我的代理类

时会发生此错误
namespace TesteWebService
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnPdv_Click(object sender, EventArgs e)
        {
            SuporteTecnicoClientProxy proxy = new SuporteTecnicoClientProxy();=> **Here error**

                try
                {
                    TPDV pdv = proxy.getCnpjParceiro(txtCnpj.Text);
                    lblRazao.Text = pdv.RazaoSocial;
                    lblEndereco.Text = pdv.Endereco;
                }
                catch (Exception ex)
                { }
                finally
                { }
        }
    }
}

我的代理类

namespace TesteWebService
{
    class SuporteTecnicoClientProxy : ClientBase<ISuporteTecnicoContract>, ISuporteTecnicoContract
    {
        public TPDV getCnpjParceiro(string _cnpj)
        {
            return this.Channel.getCnpjParceiro(_cnpj);
        }
    }
}

我的界面

[ServiceContract]
    public interface ISuporteTecnicoContract
    {
        [OperationContract]
        [WebGet(UriTemplate = "/{_cnpj}")]
        TPDV getCnpjParceiro(string _cnpj);
    }

我的App.Config

<client>
    <endpoint adress="http://localhost:4600/SuporteTecnicoService.svc" binding="webHttpBinding" contract="V99SuporteTecnicoContracts.ISuporteTecnicoContract"
              behaviorConfiguration="WebBehavior">
    </endpoint>
  </client>
  <behaviors>
    <endpointBehaviors>
      <behavior name="WebBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
  </behaviors>

真正会产生上述异常的原因。我的界面是其他项目。一个类库项目。所以,我有2个项目。 WCF项目(Web服务)和我的合同项目(POCO类和接口)。最后一个项目类库。

0 个答案:

没有答案