我已经在论坛上阅读了很多关于这些问题的答案,并且鉴于我对这个主题完全了解,如果我的问题中的任何内容都是天真的,请道歉。
我有一个ASP.NET Web应用程序应该调用WCF服务发送并返回一个字符串[all in my local]
我试图通过jQuery调用此服务,现在我无处可去。即使WCF服务在我的本地运行,我的jQuery中也找不到404-Not。
我的Web.Config文件:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
这是.svc文件
<%@ ServiceHost Language="VB"
Debug="true"
Service="TemmeTaskSchedulerService.TemmeTaskSchedulerClass "
CodeBehind="TemmeTaskScheduler.svc.vb" %>
界面
<ServiceContract()>
Public Interface TemmeTaskSchedulerInterface
<OperationContract()>
Function lstSearchProjects(ByVal environment As String) As String
End Interface
实施文件
Public Class TemmeTaskSchedulerClass
Implements TemmeTaskSchedulerInterface
Public Sub New()
End Sub
Function lstSearchProjects(ByVal environment As String) As String Implements TemmeTaskSchedulerInterface.lstSearchProjects
Return ""success "+environment
End Function
End class
我的jQuery调用如下:
$('#environment').change(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url:'http://localhost:60403/TemmeTaskScheduler.svc/lstSearchProjects',
data: '{'+'$("#environment").children("option").filter(":selected").text()' + '}',//'{"Username": "' + $("#txtName").val() + '"}',
dataType: 'text',
processData: false,
success: function (data) {
alert("success:"+data);
},
error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); }
})
});
非常感谢更正和问题! :)
答案 0 :(得分:0)
在wcf web.config文件中试试这个
<behaviors>
<endpointBehaviors>
<behavior name="webScriptEnablingBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
获取信息...转到此链接 http://msdn.microsoft.com/en-us/library/vstudio/bb763177(v=vs.100).aspx