状态500:调用WCF时System.ServiceModel.ServiceActivationException

Sre*_*nth 6 .net wcf

我试图从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; }
    }
}
Run Code Online (Sandbox Code Playgroud)

Service1.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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

当我使用名为PostMan的chrome应用程序测试服务时,我们收到以下错误: -

500 System.ServiceModel.ServiceActivationException
Run Code Online (Sandbox Code Playgroud)

我正在尝试发送格式的json: -

{ImageData:"测试字符串"}

可能是错误的原因是什么?

Mx.*_*Mx. 8

我在运行SP2013 JSOM异步函数时遇到了这个问题

clientContext.executeQueryAsync(Function.createDelegate(this, OnQuerySuccess), Function.createDelegate(this, OnQueryFail));
Run Code Online (Sandbox Code Playgroud)

并通过IIS重置解决了它.

只需以管理员身份打开Windows PowerShell即可运行iisreset.

  • 谢谢,为我解决了这个问题. (3认同)