我在 MVC 项目中托管了以下 WCF 服务:
[ServiceContract]
public interface IRegistrationService
{
[OperationContract]
[WebInvoke(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped)]
RegisterUserResponse RegisterUser(string callback, string email, string forename, string surname);
}
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class RegistrationService : IegistrationService
{
public RegisterUserResponse RegisterUser(string callback, string email, string forename, string surname)
{
//...
}
}
在 web.config 中:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="WcfServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WcfEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
</bindings> <services>
<service name="Peninsula.Online.Application.Implementations.FreemiumRegistrationService" behaviorConfiguration="WcfServiceBehavior">
<endpoint binding="webHttpBinding" name="FreemiumRegistrationService" contract="Peninsula.Online.Application.Contracts.IFreemiumRegistrationService" address="" bindingConfiguration="webHttpBindingWithJsonP" behaviorConfiguration="WcfEndpointBehavior">
</endpoint>
</service>
</services>
这是从带有 JQuery Ajax 调用“TheProjectUrl/RegistrationService.svc/RegisterUser”的原始 html 页面调用的。在我的本地机器上一切正常,但是当我尝试访问 UAT 服务器上的代码时,我收到错误:
IControllerFactory 'Project.Name.Changed.StructureMapControllerActivator' 没有返回名称为 'RegistrationService.svc' 的控制器。
我可以调用 'TheProjectUrl/RegistrationService.svc' 和 'TheProjectUrl/RegistrationService.svc?wdsl' 并获得预期的结果,但是一旦我调用 'TheProjectUrl/RegistrationService.svc/RegisterUser 它不再将其视为 WCF 服务,而是作为 MVC 控制器并尝试将其解析为这样。我假设我在 IIS 中有不同的设置,或者 UAT 服务器上未安装的设置,但找不到它是什么。
编辑:根据要求,这里是 Ajax 调用:
$.ajax({
type: "GET",
crossDomain: true,
cache: false,
async: false,
url: "TheProjectUrl/RegistrationService.svc/RegisterUser",
data: data,
dataType: "jsonp",
success: function(response) {
//...
}
});
但实际上这并不重要,因为仅仅调用 TheProjectUrl/RegistrationService.svc/RegisterUser 是行不通的。