Member 13687520 Ответов: 0

Формат Wcf JSON - при потреблении на стороне клиента появляется сообщение об ошибке.


<pre>===============WCF service which returns JSON Format ===============

namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class Service1 : IService1
    {

        public string GetData(string Id)
        {
            return ("You entered: " + Id);
        }

      
    }
}
====================

namespace WcfService1
{
   [ServiceContract]
    public interface IService1
    {
    [OperationContract]
    [WebInvoke(Method = "GET", UriTemplate = "/GetData/{Id}",
     RequestFormat = WebMessageFormat.Json,
     ResponseFormat = WebMessageFormat.Json,
     BodyStyle = WebMessageBodyStyle.Wrapped
     )]
        string GetData(string Id);

       
        // TODO: Add your service operations here
    }

}
====================Web.Config file =========
  <system.serviceModel>
   
    <services>
      <service name="WcfService1.Service1" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="WcfService1.IService1"/>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
      </service>
      
    </services> 
    
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp helpEnabled="true" automaticFormatSelectionEnabled="false"  />
        </behavior>
        
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--<protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>-->    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>


Что я уже пробовал:

<pre>Client side Code 
1. I have created web application and added service reference to the Client Project  
2. I tried creating a client Object like this - 

Service1Client a = new Service1Client();

but getting an error message :- Could not find default endpoint element that references contract 'ServiceReference_test.IService1' in the ServiceModel client 

configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found 
in the client element.


Could you please let me know what mistake am doing, I am new to WCF please help me 

0 Ответов