.net 状态 500:调用 WCF 时出现 System.ServiceModel.ServiceActivationException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19630640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Status 500 : System.ServiceModel.ServiceActivationException while calling WCF
提问by Sreekanth
I am trying to send a string from android client to .NET server. The following is the server side code :- IService1.cs
我正在尝试将一个字符串从 android 客户端发送到 .NET 服务器。以下是服务器端代码:- IService1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfImageUpload
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(UriTemplate = "/JsonData",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest)]
JsonString SendData(JsonString JsonImage);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class JsonString
{
[DataMember]
public string ImageData { get; set; }
}
}
Service1.svc.cs
服务1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfImageUpload
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public JsonString SendData(JsonString JsonImage)
{
JsonString jsonStringObject = new JsonString();
jsonStringObject.ImageData = "ImageData";
return jsonStringObject;
}
}
}
Web.config
网页配置
<configuration>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service behaviorConfiguration="Default" name="WcfImageUpload.Service1">
<endpoint address="" behaviorConfiguration="webBehavior" binding="basicHttpsBinding" contract="WcfImageUpload.IService1" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
When I test the service using a chrome application called PostMan, we get the following error:-
当我使用名为 PostMan 的 chrome 应用程序测试服务时,我们收到以下错误:-
500 System.ServiceModel.ServiceActivationException
I am trying to send the json of the format:-
我正在尝试发送格式的 json:-
{ImageData: "test string"}
{ImageData:“测试字符串”}
What could be the reason for the error?
错误的原因可能是什么?
回答by Mx.
I just had this problem while running an SP2013 JSOM asynch function
我在运行 SP2013 JSOM 异步函数时遇到了这个问题
clientContext.executeQueryAsync(Function.createDelegate(this, OnQuerySuccess), Function.createDelegate(this, OnQueryFail));
and solved it via IIS reset.
并通过 IIS 重置解决了它。
Just open Windows PowerShell as Administrator and run iisreset.
只需以管理员身份打开 Windows PowerShell 并运行iisreset.

