Why sometimes endpoint address is empty - wcf

Suppose I have a WCF Service hosted in IIS, can the address in endpoint be empty?
I saw an example at WCF Tutorial.
<system.serviceModel>
<services>
<service name="MathService"
behaviorConfiguration="MathServiceBehavior">
<endpoint address="" contract="IMathService"
binding="wsHttpBinding"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MathServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>

If endpoint address is empty, it will use BaseAddress specified by the ServiceHost when you instantiate your service.

Related

What do I need to change in web config for deploying WCF service on IIS

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
</webScriptEndpoint>
</standardEndpoints>
<services>
<service behaviorConfiguration="ServiceBehavior" name="Service">
<endpoint address="" binding="webHttpBinding" contract="IService" behaviorConfiguration="EndpBehavior"/>
</service>
</services>
</system.serviceModel>
What do I need to change in web config after deploying my WCF service on IIS?
My code is running with two projects.
Your service and contract name should be a fully qualified names.
check this

Azure web service URL issue

I wrote a simple webget service , added this code at web.config..
Then in order to access it i had to type this http://127.0.0.1/service1.svc/data?value=4
I searched all the config files but couldnt find how to get rid of service1.svc part..
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webby">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WCFServiceWebRole1.Service1" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint
address="/"
binding="webHttpBinding"
contract="WCFServiceWebRole1.IService1"
behaviorConfiguration="webby"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
If you're on Azure, you'll most likely be hosting on IIS.
This article: http://social.technet.microsoft.com/wiki/contents/articles/hosting-a-wcf-rest-service-on-iis.aspx explains nicely how to use ASP.NET routing to re-route requests for Service1.svc to your service.

what is the "behaviorConfiguration" attribute of service?

what is the "behaviorConfiguration" attribute of service?
<services>
<service name="WcfServiceNetMSMQ.Service1" behaviorConfiguration="WcfServiceNetMSMQ.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8010/WcfServiceNetMSMQ/Service1/" />
</baseAddresses>
</host>
<endpoint address ="net.msmq://localhost/private/myqueue" binding="netMsmqBinding" contract="WcfServiceNetMSMQ.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
There are 3 important sections when you configure a WCF service.
1) Defining the Services:
<services>
<service behaviorConfiguration="SOAPRESTDemoBehavior" name="SOAPRESTDemo">
<endpoint address="rest" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" binding="webHttpBinding" contract="ISOAPRESTDemo" />
<endpoint address="soap" binding="basicHttpBinding" contract="ISOAPRESTDemo" />
</service>
</services>
NOTE the value of behaviorConfiguration is a reference to a section further on in the config see below...
2) Defining the 'Service Behaviours'
<serviceBehaviors>
<behavior name="SOAPRESTDemoBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
3) Defining the 'Endpoint Behaviours'
<endpointBehaviors>
<behavior name="SOAPRESTDemoEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
All 3 sections are the basics for what you need to set up a service (although this can be done programatically).
With regard to your question the behaviorConfiguration section relates to point 2 and 3 in my points above. Its where you lay out the sort of actions you want your service to have. for example above I have said that I want to allow MetaData to be published. This will essentially create a WSDL which describes the service.
The full config is here:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<!--Set up the service-->
<services>
<service behaviorConfiguration="SOAPRESTDemoBehavior" name="SOAPRESTDemo">
<endpoint address="rest" behaviorConfiguration="SOAPRESTDemoEndpointBehavior" binding="webHttpBinding" contract="ISOAPRESTDemo" />
<endpoint address="soap" binding="basicHttpBinding" contract="ISOAPRESTDemo" />
</service>
</services>
<!--Define the behaviours-->
<behaviors>
<serviceBehaviors>
<behavior name="SOAPRESTDemoBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SOAPRESTDemoEndpointBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
It is a reference to another configuration section:
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceNetMSMQ.Service1Behavior">
</behaviors>
</serviceBehaviors>
</behaviors>
Where this section contains some global configuration for the whole service.
here's an example of it, it carries some properties of the connection of the service.
<serviceBehaviors>
<behavior name="WcfServiceNetMSMQ.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
Notice that the name in this service behavior corresponds to the one you specified earlier.
Hope that helps.
You will get this error with Behavior name is not setup correctly.
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: 'http://blabla.com/WebService/Processor.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service 'http://blabla.com/WebService/Processor.svc'. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.

WCF service dataContractSerializer maxItemsInObjectGraph in web.config

I am having issues specifying the dataContractSerializer maxItemsInObjectGraph in host's web.config.
<behaviors>
<serviceBehaviors>
<behavior name="beSetting">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyNamespace.MyService"
behaviorConfiguration="beSetting" >
<endpoint address="http://localhost/myservice/"
binding="webHttpBinding"
bindingConfiguration="webHttpBinding1"
contract="MyNamespace.IMyService"
bindingNamespace="MyNamespace">
</endpoint>
</service>
</services>
The above has no effect on my data pull. The server times out because of the large volume of data.
I can however specify the max limit in code and that works
[ServiceBehavior(MaxItemsInObjectGraph=2147483646, IncludeExceptionDetailInFaults = true)]
public abstract class MyService : MyService
{
blah...
}
Does anyone know why I can't make this work through a web.config setting? I would like to keep in the web.config so it is easier for future updates.
In your behavior section, add an endpoint behavior with the dataContractSerializer, like so:
<endpointBehaviors>
<behavior name="LargeQuotaBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</endpointBehaviors>
Then modify your endpoint to use this behavior like so:
<endpoint address="http://localhost/myservice/"
binding="webHttpBinding"
bindingConfiguration="webHttpBinding1"
contract="MyNamespace.IMyService"
bindingNamespace="MyNamespace"
behaviorConfiguration="LargeQuotaBehavior">
This should solve your problem.

WCF NetTcpBinding with mex

I'm trying to publish a wcf service using nettcpbinding. I want to publish metadata, using ?wsdl.
I added the following line to the config file:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
but I can't see the wsdl in my browser. what did I do wrong?
Thanks.
Edit: Here is the relevant part of my config file:
<system.serviceModel>
<services>
<service name="wcfcheck.service1" behaviorConfiguration="wcfcheck.Service1Behavior">
<endpoint address="" binding="netTcpBinding" contract="wcfcheck.Iservice1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="wcfcheck.Service1Behavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
I might not be accessing the right URL. I tried both http://localhost:51159/Service1.svc?wsdl and http://localhost:51159/Service1.svc/mex?wsdl, and without the '?wsdl'.
You need to use the <serviceMetadata> element.
<behaviors>
<serviceBehaviors>
<behavior name="metadataSupport">
<!-- Enables the IMetadataExchange endpoint in services that -->
<!-- use "metadataSupport" in their behaviorConfiguration attribute. -->
<!-- In addition, the httpGetEnabled and httpGetUrl attributes publish -->
<!-- Service metadata for retrieval by HTTP/GET at the address -->
<!-- "http://localhost:8080/SampleService?wsdl" -->
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
</behavior>
</serviceBehaviors>
</behaviors>
You need to publish service metadata via http for wsdl. Add the following tag to the <system.serviceModel> tag of your config file
<behaviors>
<serviceBehaviors>
<behavior name = "MetadataBehavior">
<serviceMetadata httpGetEnabled = "true"/>
</behavior>
</serviceBehaviors>
</behaviors>
You will also need to specify an http address where the service metadata in wsdl will be available from. Add this to the <service> node of your config file :
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8001" />
<add baseAddress="http://localhost:8000/Service1" />
</baseAddresses>
</host>
Then if you go to http://localhost:8000/Service1?wsdl, you should see the wsdl for your service.
You can try mexTcp binding and make sure your base address starts with net.tcp://.....