I have created simple WCF service and configured its endpoint as bellow.
<services>
<service name="AsynchWCFService.MathOperation">
<endpoint address="MathsOperation" binding="wsHttpBinding" contract="AsynchWCFService.IMathOperation">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/OperationService/" />
</baseAddresses>
</host>
</service>
</services>
I have hosted this WCF service in a stand alone exe. I am expecting that my service will be accessible at below address.
http://localhost:8080/OperationService/MathsOperation/
But service is accessible at http://localhost:8080/OperationService/
I want to access service using http://localhost:8080/OperationService/MathsOperation/ link. Can any one help me?
I don't think your service is available at http://localhost:8080/OperationService. What you see there is just a HTML page created by WCF which describes available mex endpoints or path to WSDL.
These mex endpoints describe the ABC of your WCF service where A = address => http://localhost:8080/OperationService/MathsOperation/. Potential clients know about your service url by querying the mex endpoint.
By default, this HTML page will show up at your base address. However, you can disable this page or set it to appear at some different url by using serviceDebug behavior.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug httpHelpPageUrl="http://localhost:8080/OperationService/myhelppage"
/> <!-- use httpHelpPageEnabled="false" to disable the page -->
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Unfortunately, I don't think you can set httpHelpPageUrl to same address as your service endpoint.
Related
I have a WCF service hosted in windows service.
when I am trying to access the service I am getting below error message.
No connection could be made because the target machine actively refused it 127.0.0.1:9002
Inner Exception
There was no endpoint listening at http://localhost:9002/MainService/Service that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
But endpoints has been defined in App config of WCF as below.
<system.serviceModel>
<services>
<service name="MainService.CalculatorService">
<endpoint address="CalculatorService" binding="basicHttpBinding" contract="MainService.ICalculator">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:9002/MainService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
web config of the client
<client>
<endpoint address="http://localhost:9002/MainService/CalculatorService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INoiseCalculator"
contract="Service.ICalculator" name="BasicHttpBinding_INoiseCalculator" />
</client>
In Controller I am accessing service as per below
MainService.CalculatorClient proxy = new MainService.CalculatorClient();
proxy.getDetails();
I have opened up the port in the firewall as well.
I can't figure out what's wrong because when service gets self hosted in WccSvcHost it works fine but after deployment it doesn't work.
It seems that there is something wrong with the service running state. For verifying this, we could talk about the client endpoint at first.
<client>
<endpoint address="http://localhost:9002/MainService/CalculatorService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INoiseCalculator"
contract="Service.ICalculator" name="BasicHttpBinding_INoiseCalculator" />
</client>
The contract is Service.ICalculator, while the namespace you are using to instantiate the client proxy is MainService
MainService.CalculatorClient proxy = new MainService.CalculatorClient();
proxy.getDetails();
Is the client service endpoint automatically generated by adding service reference? Why the namespace is incongruity?
I suggest you generate the client endpoint again by adding service reference on the client-side, with this, we can check if the service is working well.
About calling the service by adding service reference.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/accessing-services-using-a-wcf-client
Feel free to let me know if the problem still exists.
I have created separate solutions as follows:
Solution A - that defines and implement the service contract for service R with interface IR and project name is ALib.
Solution B - host the service contract and runs it.
When I run the host application, it runs fine, but I cannot access the url with the base address provided. I updated the App.config file as instructed inside
WCF Tutorial
Lets break down what has been updated inside the App.config file.
1. <service name="ALib.R">
2. <add baseAddress = "http://localhost:8000/A/R" />
3. <endpoint address="" binding="wsHttpBinding" contract="ALib.IR">
When I type the url "http://localhost:8000/A/R" I get HTTP 400 error, but I get the page with "http://localhost:8000/A/". This is not how it is done inside the tutorial. I have enabled the metadata as well follows:
var smb = new ServiceMetadataBehavior
{
HttpGetEnabled = true
};
selfHost.Description.Behaviors.Add(smb);
Is there anything missing from what being done so far ?
Please try the following configuration.
<system.serviceModel>
<services>
<service name="Server6.MyService">
<endpoint address="" binding="wsHttpBinding" contract="Server6.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="Server6.IService"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:13050/A/R"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"></serviceMetadata>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Feel free to let me know if there is anything I can help with.
I was working on WCF service with an endpoint binding of netTcpBinding, hosted in a console application.
These are the configuration settings:
<system.serviceModel>
<services>
<service name="FullTimePartTime_EmpWCFServiceAppl.EmployeeService"
behaviorConfiguration="mexBehaviour" >
<endpoint
address="EmployeeService"
binding="netTcpBinding"
contract="FullTimePartTime_EmpWCFServiceAppl.IEmployeeService">
</endpoint>
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:7090/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The console application executes fine. WPF is client app which should consume the WCF service, but when I tried to add a service reference, this error occurred:
Service Reference Error
Can anyone help me to fix this issue & let me know the mistake I made?
Thanks in advance.
Always the metadata discovery is through http.So you need to have one more base address for the http which publishes the metdata via http.
<host>
<baseAddresses>
<add baseAddress="http://localhost:7091/"/>
<add baseAddress="net.tcp://localhost:7090/"/>
</baseAddresses>
</host>
First try to browse the metadata through http://localhost:7091/?wsdl. Now try to generate proxy class using the service reference address http://localhost:7091/.
I know this has been asked many times, and answered many times, but, all the provided samples that should be working don't seem to want to work for me today.
When I try to start the host, I keep getting the following error:
"The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service TraceService. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract."
My service is being hosted in a managed windows service host as per Microsoft's example: http://msdn.microsoft.com/en-us/library/ms733069%28v=vs.90%29.aspx
And here is my nice and simple config:
<system.serviceModel>
<services>
<service name="Daff.Lae.Service.TraceService">
<endpoint address="" binding="wsHttpBinding" name="TraceService" contract="Contracts.Service.ITraceService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/TraceService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Of course, the problem becomes more interesting when there are no errors if I remove this line:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
Any help would be very very very greatly appreciated :)
Be sure to specify a behaviorConfiguration in the service element of your configuration in order to allow either httpGet or httpsGet.
I see that you have already defined a serviceBehavior named DefaultBehavior - now all you need to do is add behaviorConfiguration="DefaultBehavior" to the service element, so that line becomes:
<service name="Daff.Lae.Service.TraceService" behaviorConfiguration="DefaultBehavior">
If you don't explicitly specify a behavior for your service, both HTTP GETs and HTTPS GETs are disallowed by default, and your metadata will not be exposed.
As you're using WS-Http you are binding to an HTTPS protocol, so you need to use the correct MEX binding;
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
and change the baseaddress to a https one.
Or (the other way around) convert your wsHttp binding to a basicHttp binding and things will start working for you.
`<services>
<service name="MyService.Service1" behaviorConfiguration="Service1" >
</services>
`
where MyService is the application name , Service1 is the default implementation class for IService1
`
<protocolMapping>
//Remove any http or https bindings provided
</protocolMapping>
`
It should help when you use WCF Application Project
I need to consume a WCF service from a DLL, hence i don't have any configuration file to read bindings configurations from.
I'm having a really hard time getting it to work. In the end, as a very simple solution, I add a reference to the WCF and instantiate it like this:
WSHttpBinding binding = new WSHttpBinding();
EndpointAddress address = new EndpointAddress("http://myhost.net/Service.svc");
ServiceReference.ServiceClient client = new ServiceReference.ServiceClient(binding, address);
var result = client.Method1();
In localhost this simply works. When trying it from another machine, i get this error:
The request for security token could not be satisfied because authentication failed.
In the host, IIS is set to "Anonymous", so I guess it should simply work.
Any help?
EDIT: Service Config File
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<service name="Mai.MyPlanner.Service">
<endpoint address="" binding="wsHttpBinding" contract="Mai.MyPlanner.IService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://MY_SERVICE"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<connectionStrings>
<!-- PROD -->
<!-- TEST -->
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
Use this code:
WSHttpBinding binding = new WSHttpBinding();
EndpointIdentity identity = EndpointIdentity.CreateDnsIdentity("localhost");
EndpointAddress address = new EndpointAddress("http://myhost.net/Service.svc", identity);
ServiceReference.ServiceClient client = new ServiceReference.ServiceClient(binding, address);
var result = client.Method1();
You will still need to pass Dns identity value and address into your method calling this code. Also this type of configuration will work only in intranet (same windows domain) because it by defult uses message security and Windows authentication.
Use basic http binding instead, if you do not require security.
What if you'd have a ServiceHost that would take a ServiceEndpoint such as below:
// Step 3 Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(ICalculator), binding, "CalculatorService");
How would you still programmatically specify App.config elements such as:
<services>
<service name="GettingStartedLib.CalculatorService">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8000/GettingStarted/CalculatorService" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="wsHttpBinding" contract="GettingStartedLib.ICalculator">
<!--
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>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>