Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status 500 : System.ServiceModel.ServiceActivationException while calling WCF

Tags:

.net

wcf

I am trying to send a string from android client to .NET server. The following is the server side code :- 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

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:-

500 System.ServiceModel.ServiceActivationException

I am trying to send the json of the format:-

{ImageData: "test string"}

What could be the reason for the error?

like image 696
Sreekanth Avatar asked Oct 28 '13 09:10

Sreekanth


1 Answers

I just had this problem while running an SP2013 JSOM asynch function

clientContext.executeQueryAsync(Function.createDelegate(this, OnQuerySuccess), Function.createDelegate(this, OnQueryFail));

and solved it via IIS reset.

Just open Windows PowerShell as Administrator and run iisreset.

like image 185
Mx. Avatar answered Nov 16 '22 18:11

Mx.