Could not find default endpoint element while acessing WCF service - wcf

I am unable to consume the wcf restful service hosted in IIS.i.e at http://192.168.100.87:7001/ProductRESTService.svc/.
I have created a client application and added the service reference and created the proxy for service and accesing the using prxoy.
The error is:
Could not find default endpoint element that references contract 'ServiceReference2.IProductRESTService' 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.
My web.config file of service is following.
<system.serviceModel>
<services>
<service name="MyRESTService.ProductRESTService" behaviorConfiguration="serviceBehavior">
<endpoint address=""
binding="webHttpBinding"
contract="MyRESTService.IProductRESTService"
behaviorConfiguration="web"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
hi, please check my client configuration file.
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICreate_Restful_WCF_Service"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://192.168.1.xxx:2777/ProductRESTService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICreate_Restful_WCF_Service" contract="ServiceReference1.IProductRESTService" name="BasicHttpBinding_ICreate_Restful_WCF_Service"/>
</client>
</system.serviceModel>
</configuration>

Why do you use client applicatin for rest service? For rest service, we could call it directly by httpWebRequest. Add Service Reference uses WSDL or ws-metadataExchange, and rest does not have metadata. If you use add service reference, it will not generate any app.config settings, and it will produce this error. If you want to try add service reference to use wcf service, you need to use soap service instead of rest service.

Related

How to increase maxquerystringlength and maxquerylength in wcf rest services?

I had written this code in wcf service web config file,i had communicating my sql server from android application using this service,i am sending request from android application using httppost method but its showing querystring is beyond the length. Can we increase length by using any other property,because i want to send larger input so that is there any chance to send or else i have to restrict my query string
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<httpRuntime maxQueryStringLength="2097151" maxUrlLength="2097151"/>
</system.web>
<connectionStrings >
<add name="DBConnection" connectionString="Integrated Security=true;Data Source=LENOVO\SQLEXPRESS;Initial Catalog=Order160415" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.serviceModel>
<services>
<service name="JsonWcfService.GetEmployees" behaviorConfiguration="EmpServiceBehaviour">
<endpoint address ="" binding="webHttpBinding" contract="JsonWcfService.IGetEmployees" behaviorConfiguration="web">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="EmpServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
</configuration>
You can define a binding configuration for the webHttpBinding and assign it to the endpoint, just like any other binding. To do this, add something like the following to your <system.serviceModel> section in the config file:
<bindings>
<webHttpBinding>
<binding name="MyWebHttpBinding"
maxBufferPoolSize="2097151"
maxBufferSize="2097151"
maxReceivedMessageSize="2097151">
<readerQuotas maxStringContentLength="2097151" />
</binding>
</webHttpBinding>
</bindings>
I set the values equal to what you set in the <httpRuntime> element in your posted config.
The final step is to assign this binding configuration to your service endpoint using the bindingConfiguration attribute in the service element:
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration="MyWebHttpBinding"
contract="JsonWcfService.IGetEmployees"
behaviorConfiguration="web">
To sum up:
Create a binding configuration definition in the web.config file with the values you want.
Assign the binding configuration definition (using the name attribute) to the bindingConfiguration attribute in the <service> element.
In the absence of a binding configuration definition (and its assignment to an endpoint), WCF will use the default values for the binding protocol specified. In this case, the default values would be 524,288 for maxBufferSize and maxBufferPoolSize, 65,536 for maxReceivedMessageSize and 8,192 for maxStringContentLength, which are all smaller than the 2,097,151 limit you set in the <httpRuntime> element.
These settings are specific to the WCF service (or client, if it's in the client config), so even if IIS will accept the larger message, WCF will reject it if it exceeds the limits defined by the binding.
For more information, see on MSDN.

Cannot obtain Metadata from http://localhost:12659

in my config my address details as follows net.tcp://127.0.0.1:1127/CalculatorService but when the error message is showing Cannot obtain Metadata from http://localhost:12659
i have simple service with tcp binding and i am running my service from VS2010 IDE with wcf test client and then i am getting this error Cannot obtain Metadata from http://localhost:12659
here is my config file details
<?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation. All Rights Reserved.-->
<configuration>
<system.serviceModel>
<services>
<service name="MyTcpActivation.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:1127/CalculatorService/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="netTcpBinding" bindingConfiguration="PortSharingBinding"
contract="MyTcpActivation.ICalculator"/>
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="PortSharingBinding" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true"/></system.web>
</configuration>
please help me to run my service from wcf test client from VS2010 IDE. thanks
This suggests an activation problem on WCF. Metadata are not exposed when there is a problem in your service/config/env.
To get the error message try to open http://localhost:12659 in your browser and/or check event logs.
As it's a nettcpbinding, the config is a little more complex especially if your are hosting the service under IIS : check that WAS Service is started, Net Tcp Listener Service is Started, net.tcp is in Activated protocols for your web site, configured bindings conftoins ntc.tcp on port 1127 , ...). You may also try a basicHttpBinding first.
For debugging purposes set the includeExceptionDetailInFaults attribute to true
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>

Configuring REST WCF Service Over SSL

I am building a WCF Restful Web Service and currently, I am transferring data over http. Now, I want to transfer the data securely over https. What shall I change in my config file to enable this please? This is my current config file:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="MyService.DBService" behaviorConfiguration="ServiceBehaviour">
<endpoint address ="" binding="webHttpBinding" contract="MyService.IDBService" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
You will have to configure transport layer security by defining a customized and refer that in your endpoint using bindingConfiguration. Check this out about configuring security. Once you have this configure an SSL certificate in your IIS to complete this. You can refer to this to see how to configure SSL certs with IIS.

Hosting a WCF service using net tcp binding. Error: Service metadata may not be accessible

I have a Service Application which has the following web.config file:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<standardEndpoints>
</standardEndpoints>
<bindings>
</bindings>
<services>
<service behaviorConfiguration="metadatabehaviour" name="WCF_Service.HistorianService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
contract="WCF_Service.IHistorianCollectorService" />
<endpoint address="net.tcp://localhost:8081/mex" binding="mexTcpBinding"
contract="IMetadataExchange" />
<endpoint address="net.tcp://localhost:8081" binding="netTcpBinding"
contract="WCF_Service.IHistorianCollectorService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadatabehaviour">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
And I am getting the following error: Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
I can successfully run the service if I am just implementing the "basicHttpBinding" but as soon as I introduce a "netTcp" binding, I start getting this error. I have changed the 'mex' binding to 'mexTcpBinding' but still the error persists.
I have tried toggling the relevant properties. Any idea how I can correct this error?
It seems you actually disabled metadata exchange:
<serviceMetadata httpGetEnabled="false" />
It should be set to true!
I found out the solution. My port number for net.tcp had value '0'. I didnt know that was possible. Changing it to 808 did it.

WCF over IIS through load balancer reports wrong base address

I'm trying to launch a WCF service over SSL on IIS 6 through a load balancer. My initial problem was an obvious and pretty well discussed one - the address shown on the WSDL page pointed to https://SERVERNAME/WebServices/mydomainws.svc instead of www.mydomain.com. The answer to this problem is to add a host header value in IIS. I did that and it worked... sort of. I now get http://www.mydomain.com/WebServices/mydomainws.svc when viewing the wsdl in a browser. If I click on that link (the non-ssl link) I get a service definition that again references the server name.
The next oft recommended remedy is to use WCF Extras which provides an extension that allows you to specify a base address. But setting that config entry only updated the soap12:address. The EndPointReference address is still using the machine name.
To summarize: WSDL as viewed in web browser at https://www.mydomain.com/WebServices/mydomainws.svc: http://www.mydomain.com/WebServices/mydomainws.scv
Clicking the above link brings me to an actual wsdl file with the following service entry:
https://ServerName/WebServices/mydomainws.svc
My server config file has the following serviceModel entries:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<message clientCredentialType="None"/>
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="mydomain.ws.mydomainws" behaviorConfiguration="mydomainwsBehavior">
<!-- Service Endpoints -->
<endpoint address="" **behaviorConfiguration="CorrectEndPoint"** binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="mydomain.ws.Imydomainws"/>
<endpoint address="mex" **behaviorConfiguration="CorrectEndPoint"** binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mydomainwsBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
**<behavior name="CorrectEndPoint">
<wsdlExtensions location="https://www.mydomain.com/WebServices/mydomainws.svc" singleFile="true"/>
</behavior>**
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<extensions>
<behaviorExtensions>
<add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
Can anyone point me in the right direction?
Thanks,
George
This should be handeled by new behavior useRequestHeadersForMetadataAddress. Try to add this to your service behavior:
<serviceBehaviors>
<behavior name="LoadBalancedBehavior">
<serviceMetadata httpGetEnabled="true" />
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="80" />
<add scheme="https" port="443" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
<!-- Other service behaviors as necesary -->
</behavior>
</serviceBehaviors>
This behavior is availabel in WCF 4.0 and should be available as KB for WCF 3.x.