How to configure webHttp Binding while creating a WCF service in Azure? - c#

I am developing a WCF WebRole service in Azure and need to invoke a method that to give employee data in JSON format.But unlike a normal WCF Web Service, I dont know how to configure the "Web.config" for WCF Webrole and my code "Web.config" for normal WCF service is below:
<system.serviceModel>
<services>
<service name="empl.Service1" behaviorConfiguration="empl.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="webHttpBinding" contract="empl.IService1" behaviorConfiguration="web">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="empl.Service1Behavior">
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
And my code "Web.config"for WCF WebRole (Azure)is as follow
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /></system.serviceModel>
Now I need to get the URI access "http://localhost/Service1.svc/GetId" where it should respond in JSON data. But for me it is showing that "HTTP400 Bad Request". Help me out.

The bad request might be that the request being sent is not valid. If your service was not accessible or found it would have been a different Http error code. Try enabling tracing on your service to see the cause for bad request. To enable tracing follow this link

Related

Adding service/endpoint behaviors to multiple services through config

In my project, there are multiple WCF services exposed. I want to add a service and endpoint behaviors to all of these services.
I have created these behaviors like below.
<behaviors>
<endpointBehaviors>
<behavior name="RequestInspectorBehavior">
<RequestInspectorBehaviorExtension />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="webby">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<RequestInspectorBehaviorExtension />
</behavior>
</serviceBehaviors>
</behaviors>
Now one option is, I can add these to my individual services like below.
<service name="Service1" behaviorConfiguration="webby">
<endpoint address="" behaviorConfiguration="RequestInspectorBehavior" binding="webHttpBinding" contract="CONTRACT_GOES_HERE" />
But what I would like to know that is there a way I can provide this service and endpoint behaviors to all my services without explicitly adding these via names for each service.
With WCF 4.0+, you can set a behavior as the default for all services and/or endpoints by omitting the name attribute in the appropriate behavior section of your config. This is also true for bindings.
In your situation, the following should work:
<behaviors>
<endpointBehaviors>
<behavior>
<RequestInspectorBehaviorExtension />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<RequestInspectorBehaviorExtension />
</behavior>
</serviceBehaviors>
</behaviors>
As both the endpoint and service behaviors do not have a name attribute, they will be used for as the default for all service and endpoint behaviors.
So your service and endpoint definitions would look like this:
<service name="Service1">
<endpoint address=""
binding="webHttpBinding"
contract="CONTRACT_GOES_HERE" />
If you have a service or endpoint that needs something other than the defaults you defined, you simply add definitions and then reference them in the service or endpoint element's appropriate attribute.
Default endpoints, bindings and behaviors are very powerful and useful (though they've caused their share of headaches as well). For more information you can take a look at A Developer's Introduction To Windows Communication Foundation 4.

Restful Wcf Service Issue at the consuming end

I have developed a WCF service in VS2010.EVery thing is working fine.But when i have converted to restful service,not working at the consuming end(Console application).
Getting Error:The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified.
web.config settings of WCF restful service:
<services>
<service behaviorConfiguration="DashBoardService.Service1Behavior"
name="DashBoardService.Service1">
<endpoint address="" binding="webHttpBinding" contract="DashBoardService.IDashBoard" behaviorConfiguration="Web">
<!--behaviorConfiguration="restfulBehavior" ,behaviorConfiguration="Web"-->
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DashBoardService.Service1Behavior">
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
Dont know where am doing wrong.Please help me out of this.

Error in wcf service

I am using a wcf service to provide some data to my clients to plot a graph .I have seen some thing and created the service But when I run it is showing following error.How to over come it?
The type 'WcfService2.Servi', provided as the Service attribute value in theServiceHostdirective, or provided in the configuration elementsystem.serviceModel/serviceHostingEnvironment/serviceActivationscould not be found.
this is my web.config file
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfService2.Servi" behaviorConfiguration="WcfService1.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="webHttpBinding" contract="WcfService2.Servi" behaviorConfiguration="web" bindingConfiguration="crossDomain">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService1.Service1Behavior">
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Your service contract type is called WcfService2.Servi. This looks like a typo. If you correct this, does the service work?

WCF over Http and Https resolving local address in WSDL

Recently we added HTTPS to one of our WCF services that is exposed over REST and SOAP endpoints.
When we made this modification, the SOAP endpoints are experiencing issues that I am unable to find fixes for.
The problem I am having right now is that when the HTTP endpoint is consumed, the SOAP address given in the WSDL is pointing to the local address. This is not allowing the service to be consumed over HTTP and only of HTTPS.
The web.config is the following for the relevant section:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpsBinding">
<security mode="Transport"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MyServiceBehavior"
name="Some.Path.To.MyService">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="basicHttpsBinding"
contract="Some.Path.To.IMyService"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PingPostServiceBehavior">
<serviceThrottling maxConcurrentInstances="800"
maxConcurrentCalls="800"
maxConcurrentSessions="800"/>
<!--<useRequestHeadersForMetadataAddress/>-->
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="false"/>
</behavior>
</serviceBehaviors>
When I go to the PRODUCTION HTTP WSDL address, the local address is given in the soap address element as shown in following image. I apologize about the bad censor job.

how to register a web service in iis?

I have a web service made in c# and I want to know how to register it in IIS for consumption from another app. I know how to consume it from the same solution but this isn't the same case. Searching the internet, I've only found how to register an app.
A web service is treated like any other website in IIS. Simply convert the site to an application and pick the appropriate .Net framework version.
After you have setup the website for web service you need to do some setting in your web.config. I guess you might be missing them
Add service to the web.config like following
<services>
<service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
</endpoint>
</service>
</services>
Also add service behaviour and endpoint behaviour
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>

Categories

Resources