Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

SharePoint 2013 WCF, An HTTP Content-Type header is required for SOAP messaging and none was found

$
0
0

Hi, 

I am using SharePoint Foundation 2013 and I am trying to create a sample WCF service.

The service currently just has the default GetData() method.

I can browse to the service in the browser and add it into the wcftestclient, however when I try to invoke the method I get the following error:

"An HTTP Content-Type header is required for SOAP messaging and none was found.

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IService.GetData(Int32 value)
   at ServiceClient.GetData(Int32 value)"

I am new to WCF so I am unsure where I am going wrong. I have searched various places and haven't been able to come up with anything.

Code is as follows:

- IService.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WCF.Code
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        string GetSiteName();

    }
}

- Service.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Microsoft.SharePoint;

namespace WCF.Code
{
    using Microsoft.SharePoint.Client.Services;
    using System.ServiceModel.Activation;
    using Microsoft.SharePoint;
    using System.Data.SqlClient;
    [ServiceBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    
    public class Service : IService
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public string GetSiteName() 
        {
            return string.Format("Current Site Name is: {0}", SPContext.Current.Web.Title);
        }
    }
}

- SampleService.svc

<%@ ServiceHost 
    Language="C#" 
    Debug="true" 
    Service="WCF.Code.Service, $SharePoint.Project.AssemblyFullName$" 
    CodeBehind="Service.cs" %>

- Web.Config

<configuration><system.web><customErrors mode="Off"/></system.web><system.serviceModel><bindings><basicHttpBinding><binding name="customBasicHttpBinding"><security mode="TransportCredentialOnly"><transport clientCredentialType="Ntlm"/></security></binding></basicHttpBinding></bindings><behaviors><serviceBehaviors><behavior name="customBasicBehavior"><serviceMetadata httpGetEnabled="true" /><serviceDebug includeExceptionDetailInFaults="false" /></behavior></serviceBehaviors></behaviors><services><service behaviorConfiguration="customBasicBehavior"
        name="WCF.Code.Service"><endpoint address="" binding="basicHttpBinding"
        bindingConfiguration="customBasicHttpBinding"
        contract="WCF.Code.IService"><identity><dns value="localhost" /></identity></endpoint><endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /></service></services></system.serviceModel></configuration>

I have some screenshots of the error but I wasn't able to post image links.

Thanks :)



Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>