0

I've my RESTful service hosted here .

I can use it perfectly with get&post http request.

How can I use as "service reference" in a Visual Studio project? I have added it in my test project and I see the methods correctly, but, when I try to call on of them, I get the "could not find default endpoint element that references contract in the servicemodel client" error, with http code 404.

So, I'm trying to modify my web.config file, but I get only different errors. For example, now I have try to add a SOAP endpoint,but I get a "bad request" error.

This is one of my methods (they are defined in the same way)

[OperationContract]
[WebGet(UriTemplate = "impianto.json?retista={codret}&storeID={storeID}&H={hashedString}", ResponseFormat = WebMessageFormat.Json)]
List<WrapImpianti> GetImpiantoJSON(string codret, string storeID, string hashedString);

and this is the web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
    <add key="ServerAddress" value="37.59.146.241:8099/isOverviewExport.svc" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="isOverviewExport.Service1" behaviorConfiguration="MyBehavior">
          <endpoint address="soap" behaviorConfiguration="soapBehavior" binding="basicHttpBinding" name="s" contract="isOverviewExport.isOverviewExport"/>

        <endpoint address="rest" behaviorConfiguration="restBehavior" binding="webHttpBinding" name="base" contract="isOverviewExport.isOverviewExport">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="SecurityByTransport" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <extensions>
      <behaviorExtensions>
        <add name="CorsSupport" type="WebHttpCors.CorsSupportBehaviorElement, WebHttpCors, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restBehavior">
          <!--<enableWebScript/>-->
          <webHttp helpEnabled="true" />
          <CorsSupport />
        </behavior>
        <behavior name="soapBehavior">



        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior  name="MyBehavior">>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="123456" />
        </behavior>

      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
  </system.serviceModel>
  <system.webServer>

    <directoryBrowse enabled="true" />

  </system.webServer>
  <connectionStrings>
    <add name="Entities" connectionString="metadata=res://*/AccessData.Model.csdl|res://*/AccessData.Model.ssdl|res://*/AccessData.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myds;initial catalog=mydb;persist security info=True;user id=myuser;password=mypwd;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

You can also try yourself adding the service reference (the link is the same as above, http://37.59.146.241:8097/isOverviewExport.svc ). Why the second line of this snippet gives me the error I wrote above?

    var svc = new ServiceReference5.isOverviewExportClient();
    var ret = svc.GetImpiantoXML("123456", "AAA111", "test");

So, how can I use it as service reference in VS? I was thinking I have to set the soap endpoint, but maybe it isn't correct. Can you help me? :)

Piero Alberto
  • 3,823
  • 6
  • 56
  • 108

0 Answers0