Hide one WCF service in wsdl - c#

I have my own wsdl with few methods.
They are visible in e.g. SoapUI.
I want to implement new service, but I want to hide it from wsdl, but I want to call it.
Is that possible?

Yes it is. Just tell WCF you do not want to expose metadata in the service configuration:
<system.serviceModel>
<services>
<service behaviorConfiguration="MyServiceBehavior" name="MyService">
<endpoint address="http://MyService:8888" binding="wsSomeBinding" contract="IMyServiceContract" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

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.

WCF Service - Endpoint is not showing

I have a WCF Service where it has one endpoint and I have the service contract and operation contract setup in the config file but when I run the service, it cannot find the endpoint although I configured it in the web.config.
This service will be setup in IIS so I have no base address setup.
The ServiceContract has a configuration name of agent_port_type and the service behavior has a configuration name of agent_service. I am using basicHttpBinding.
Below is a copy of part of my config file:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ETAOutboundServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="Metadata">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ETAOutboundServiceBehavior" name="agent_service">
<clear />
<endpoint address="" name="agent_interface" binding="basicHttpBinding" contract="agent_port_type"
listenUriMode="Explicit" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
listenUriMode="Explicit" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Any help would be appreciated. I had it working on a different service fine but then I used svcutil to create agent_port_type and it is not working.
You should try simplifying the config to something that Works, then add extra options as need.
Start With:
Remove Clear tag
Remove all References to HTTPS
Remove listenURIMode
Add an address for the endpoint
Check the IIS log that you are calling the service that you think you are calling
Add a syntax error to Your config and check that it fails (to make sure that the config file you are editing is the one being used)

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.

hosting Wcf service via ServerHost in IIS,Console or winform App can add reference?

Hosting in IIS,web.config
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true">
</compilation>
<authentication mode="Forms"/>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AllenBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
<serviceThrottling maxConcurrentCalls="1000" maxConcurrentSessions="1000" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="jqueryWCF.WCFservice" behaviorConfiguration="mexBehavior">
<host>
<baseAddresses>
<add baseAddress="http://127.0.0.1:9999/Service"/>
</baseAddresses>
</host>
<endpoint address="" behaviorConfiguration="AllenBehavior" binding="webHttpBinding" contract="jqueryWCF.WCFservice" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
1 web page access success by JQuery ajax
2 Metadata is also released, the URL access success;
*But why the console app add service reference will appear "object reference not set to an instance of an object"????*
Looks like something wrong with metadata of your WCF service.
Check operations contracts definition.
Do not you have conflicting contract names?
Try to use ServiceModel Metadata Utility Tool (Svcutil.exe) to generated client code from WSDL instead of Visual Studio tool

WSDL file is missing for WCF WebService

I created simple wcf service with default functionality and hosted in IIS7. Its working fine and rendering data to the client. But when I try to click on wsdl link in the service its showing "Page cannot be displayed".Let me know what will be the problem
.
When I try to click the link below (http://win-nsms.smsserver.com/VirtualFolder/MyService.svc?wsdl), WSDL file is not getting displayed in the browser. Instead I am getting "The page cannot be displayed" error in the page
Now If I change the "win-nsms.smsserver.com" to "localhost" in the URL, WSDL file is getting displayed.
Yes I added behaviour configuration in my config as follows
<system.serviceModel>
<services>
<service name="WcfServiceSample.Service1" behaviorConfiguration="WcfServiceSample.Service1Behavior">
<endpoint address="" binding="wsHttpBinding" contract="WcfServiceSample.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://win-nsms.smsserver.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceSample.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
Have you allowed retrieval of service meta data?
In the behaviours section of your config file, add a new behaviour like this:
<behaviors>
<serviceBehaviors>
<behavior name="HttpGetMetadata">
<serviceMetadata httpGetEnabled="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
Then tell your service to use this behaviour:
<system.serviceModel>
<services>
<service name="MyService"
behaviorConfiguration="HttpGetMetadata">
....
This is telling your service to allow the service metadata (the WSDL) to be retrieved via http. To confirm you can browse to the appropriate URL.
Is "mymachinename.domainname.com" added as a hostmask in IIS for the site?
You may need to setup the base address for the service.
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://mymachinename.domainname.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
I had a similar problem where the service was working 100% for domain.com but not www.domain.com. I had to setup the latter as a redirect to the former and set the base address to the former.
HTH!
Did you enable WDS exposure? Standard settings dont show the WDSL.

Categories

Resources