gpt4 book ai didi

ajax - 对 WCF 休息服务进行 Ajax 调用时出现 500 System.ServiceModel.ServiceActivationException

转载 作者:行者123 更新时间:2023-12-04 01:57:23 26 4
gpt4 key购买 nike

Ajax 调用:

   $.ajax({
type: "POST",
url: "http://SomeService/ServiceName.svc/GetSearchResults",
data: JSON.stringify({ parameters: serviceParameters }),
contentType: "application/json; charset=utf-8",
dataType: "XML",
success: function (response) {
$("#xmlText").text(response.xml);
},
error: function (msg) {
alert(msg.toString);
}
})

WCF接口(interface):
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Json,
UriTemplate = "GetSearchResults")]
XElement GetSearchResults(inputParameters parameters);

[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, UriTemplate = "getFile")]
Stream GetFile(DocInfo info);

网络配置:
 <system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>

<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>

该服务托管在 IIS6 上。

当我调用该服务时,我收到以下错误消息:
500 System.ServiceModel.ServiceActivationException

我可以调用 GetFile方法并获取响应流,但在调用 GetSearchResults 时收到错误消息.

任何帮助将不胜感激。

最佳答案

非常感谢您鼓舞人心的回复和评论。

我实际上遇到了同样的错误,但故事不同:

起初,我收到“404(未找到)”服务器错误,这是因为我没有用于“HTTPS”的传输,而我已经有用于“HTTP”的传输。

我添加了 <httpsTransport>给我的<binding>元素,所以它看起来像这样:

<bindings>
<customBinding>
<binding name="CustomBinding_ITheService">
<httpTransport keepAliveEnabled="True" transferMode="Streamed" authenticationScheme="None" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" manualAddressing="true" />
<httpsTransport keepAliveEnabled="True" transferMode="Streamed" authenticationScheme="None" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" manualAddressing="true" />
</binding>
</customBinding>
</bindings>

然后我得到了 500 System.ServiceModel.ServiceActivationException错误。但是,我浏览了“事件查看器 > Windows 日志 > 应用程序”,发现“对于同一个绑定(bind),不能多次定义传输”。因此,我决定为“HTTPS”传输添加一个带有新绑定(bind)的附加端点。

最后,我的配置如下所示:
<services>
<service name="TheService" behaviorConfiguration="WebHttpBehavior_ITheService">
<endpoint binding="customBinding" bindingConfiguration="CustomBinding_ITheService" contract="ITheService" behaviorConfiguration="EndPointBehavior_ITheService" />
<endpoint binding="customBinding" bindingConfiguration="CustomBinding_ITheService_Secured" contract="ITheService" behaviorConfiguration="EndPointBehavior_ITheService" />
</service>
</services>

<bindings>
<customBinding>
<binding name="CustomBinding_ITheService">
<httpTransport keepAliveEnabled="True" transferMode="Streamed" authenticationScheme="None" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" manualAddressing="true" />
</binding>
<binding name="CustomBinding_ITheService_Secured">
<httpsTransport keepAliveEnabled="True" transferMode="Streamed" authenticationScheme="None" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" manualAddressing="true" />
</binding>
</customBinding>
</bindings>

然后每件事都按正确的方式进行并完美运行。

如果您在 Visual Studio 上开发并使用 IIS-Express“Cassini”,请记住在网站项目的属性中启用 SSL 选项,这会告诉 IIS-Express 为您之前添加到绑定(bind)的 HTTPS 传输准备一个基本 URL .

关于ajax - 对 WCF 休息服务进行 Ajax 调用时出现 500 System.ServiceModel.ServiceActivationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11899881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com