我已经使用 ASP.NET 4 创建了一个 WCF 服务,并试图在我自己的 Web 应用程序项目中连接到它,这给了我“找不到默认端点元素”错误。
这个类似问题的答案似乎都对我没有帮助,因为它们似乎都在处理一个引用该服务并且缺少配置文件的外部项目。
该服务在直接使用其方法时起作用(例如:JS 调用)。
有任何想法吗?请在下面查看我的 serviceModel 部分:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled = "true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<services>
<service name="MapiWebService.CrmService" behaviorConfiguration="metadataBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:64049/Service/CrmService.svc"/>
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="MapiWebService.CrmService" behaviorConfiguration="webHttpBehavior" />
<endpoint address="http://localhost:64049/Service/CrmService.svc/mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
这是我的服务课程的开场白:
namespace MapiWebService
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CrmService : PortalService
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public string Authenticate(string username, string password)