Asp.net mvc 在API项目中使用类库中的服务时遇到问题
我已经创建了一个类库项目,并将“E-Verify”web服务的服务引用添加到此项目中。在这个项目中,我创建了一个包装器类并使用了“E-Verify”的所有服务 我在API项目中添加了对该项目的引用。但是,在API项目中评估此包装器方法时,我得到了一个错误 错误: 在ServiceModel客户端配置部分中找不到引用约定“EmployerWebServiceV29.IEEmployerWebServiceV29”的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此约定匹配的端点元素 有人知道如何解决这个问题吗 包装器代码:Asp.net mvc 在API项目中使用类库中的服务时遇到问题,asp.net-mvc,web-services,asp.net-web-api,Asp.net Mvc,Web Services,Asp.net Web Api,我已经创建了一个类库项目,并将“E-Verify”web服务的服务引用添加到此项目中。在这个项目中,我创建了一个包装器类并使用了“E-Verify”的所有服务 我在API项目中添加了对该项目的引用。但是,在API项目中评估此包装器方法时,我得到了一个错误 错误: 在ServiceModel客户端配置部分中找不到引用约定“EmployerWebServiceV29.IEEmployerWebServiceV29”的默认终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此约
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);
}
<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_IEmployerWebServiceV29"
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>
app.config:
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);
}
<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_IEmployerWebServiceV29"
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>
请编辑您的答案以包含代码/配置,不要将其作为您自己问题的注释发布。是否可以在API项目中调用类库项目中定义的服务?如果可能的话,你能建议我如何做到这一点吗?这是可能的,是的。但是你有一个“未知”问题需要解决,除非你在问题中提供一个答案(通过单击“编辑”并将其添加到问题正文中),以便其他人可以复制,否则这里的人将无法帮助你解决这个问题。您在问题上投入的精力越多,您就越有可能得到足够的答案。请编辑您的答案以包含代码/配置,不要将其作为注释发布到您自己的问题中。是否可以在API项目中调用类库项目中定义的服务?如果可能的话,你能建议我如何做到这一点吗?这是可能的,是的。但是你有一个“未知”问题需要解决,除非你在问题中提供一个答案(通过单击“编辑”并将其添加到问题正文中),以便其他人可以复制,否则这里的人将无法帮助你解决这个问题。你在问题上投入的精力越多,就越有可能得到充分的答案。