在API项目中使用类库中的服务时遇到问题

时间:2017-10-05 10:37:43

标签: asp.net-mvc web-services asp.net-web-api

我创建了一个类库项目,并将“E-Verify”Web服务的服务引用添加到此项目中。在这个项目中,我创建了一个包装类并使用了“E-Verify”的所有服务。

我在API项目中添加了对该项目的引用。但是,在评估API项目中的这个包装器方法时,我收到了一个错误 错误:

  

在ServiceModel客户端配置部分中找不到引用合同“EmployerWebServiceV29.IEmployerWebServiceV29”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。

任何人都知道如何解决这个问题?

包装代码:

try { 
    EmployerWebServiceV29Client client = new EmployerWebServiceV29Client(); 
    client.ClientCredentials.UserName.UserName = ""; 
    client.ClientCredentials.UserName.Password = "";
    client.VerifyConnection(); 
} catch (Exception ex) { 
    throw new ServiceAccessException(ErrorConstants.SERVICE_ACCESS_ERROR); 
}

的app.config:

<bindings> 
    <basicHttpBinding> 
        <binding name="BasicHttpBinding_IEmployerWebServiceV29">
            <security mode="TransportWithMessageCredential"/> 
        </binding> 
    </basicHttpBinding> 
    <wsHttpBinding>
        <binding name="CustomBinding_IEmployerWebServiceV29">
            <security mode="TransportWithMessageCredential"> 
                <transport clientCredentialType="None"/> 
                <message clientCredentialType="UserName"/> 
            </security> 
        </binding> 
    </wsHttpBinding> 
</bindings>

<client>
    <endpoint address="stage.e-verify.uscis.gov/WcfWebService/…;"
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IEmployerWebServiceV2‌​9"
              contract="EmployerWebServiceV29.IEmployerWebServiceV29"
              name="BasicHttpBinding_IEmployerWebServiceV29"/>
    <endpoint address="stage.e-verify.uscis.gov/WcfWebService/…;"
              binding="wsHttpBinding"
              bindingConfiguration="CustomBinding_IEmployerWebServiceV29"
              contract="EmployerWebServiceV29.IEmployerWebServiceV29"
              name="CustomBinding_IEmployerWebServiceV29"/>
</client>

0 个答案:

没有答案