WCF Service Hosted on IIS10. Can browse the .svc file but the wsdl does not show up - vb.net

I have a test WCF service that I hosted on IIS. I added a new application to the default website and used default app pool to host my test service. I am able to browse the .svc file from the content view in IIS and the success page along with a link to wsdl opens up on Windows IE. However, on clicking the wsdl link, a HTTP 404(Not found) error is thrown.(everything is on my localhost being accessed internally)
I have added the metadata endpoint and this is the relevant portion of my web.config file.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehaviour" name="ClassLibrary1.HelloWorldService">
<endpoint address="HelloService" binding="basicHttpBinding" bindingConfiguration=""
contract="ClassLibrary1.IHelloWorldService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:17000"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
Can someone please guide me about what I can be missing? Could it be a permissions issue or anything else?
Thanks.

There is no need to add the base address to service contract which will be provided by the IIS web server.
The default wcf application configuration enable the service metadata and we are able to access the metadata by the svc page or we directly use the following url.
http://localhost:90/Service1.svc?wsdl
Feel free to contract me If the problem still exists.

Related

why I can't access wcf hosted in windows service?

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.

WCF web service not working after deployed

I am trying to create a WCF web service which will allow other applications to retrieve a string by making a http request to this service url. I tried publishing the service in IIS and when attempting to browse to it, using the url, it says it
' The resource cannot be found'
when I checked the path to the folder I used the url,
and I get the error
'No protocol binding matches the given address
'http://localhost:xxxx/WcfSampleLibrary/Service1/mex.'
Protocol bindings are configured at the Site level in IIS or WAS configuration'
Here is the directory path of the published folder:
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\WcfSampleLibrary.Service1
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\Web.config
C:\inetpub\wwwroot\WcfServices\WcfSampleLibrary\bin\WcfSampleLibrary.dll
The web config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfSampleLibrary.Service1" behaviorConfiguration ="mex">
<host>
<baseAddresses>
<add baseAddress = "http://192.xxx.x.xxx/WcfSampleLibrary/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address =""
binding="wsHttpBinding" contract="WcfSampleLibrary.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<endpoint address="http://localhost:xxxx/WcfSampleLibrary/Service1/mex" name="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mex">
<serviceMetadata httpGetEnabled="false"/>
<!-- 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>
</behaviors>
In IIS-hosted WCF services you don't specify a full URI in the address. IIS decides the address. Also the baseAddresses element is completely ignored when hosting in IIS (so remove it from you Web.config). The service's base address is determined by the web site & virtual directory into which your wcf service is placed.Do something like this:
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
Then your address would be http://IIS.SERVER/SiteName/Folder/WcfSampleLibrary.Service1.svc. If you're not sure what the address is, use your IIS Administration tool, select the site that has the service in it, Right-click and choose Advanced -> Browse Site.
Also, I'd turn on httpGetEnabled on your mex behavior--if you want to publish your WSDL. This makes it easier to consume your service as you are developing it:
<behaviors>
<serviceBehaviors>
<behavior name="mex" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
With httpGetEnabled being on, browsing to your service URI will give you an option to see the WSDL.

WCF unable to find netTcpBinding

I am trying to create a WCF service that is accessible through both webHttpBinding and netTcpBinding. I have been successful in getting the webHttpBinding to be accessible through a Java client and now I'm working on trying to get the netTcpBinding working.
I have set up the configuration like this;
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="httpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="MR_Jukebox_Service.JukeboxService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/MR_Jukebox_Service/"/>
<add baseAddress="net.tcp://localhost:8523/Design_Time_Addresses/MR_Jukebox_Service/net/"/>
</baseAddresses>
</host>
<endpoint address=""
behaviorConfiguration="httpBehavior"
binding="webHttpBinding"
contract="MR_Jukebox_Service.IJukeboxService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="MR_Jukebox_Service.IJukeboxService" />
<endpoint address="net.tcp://localhost:8523/Design_Time_Addresses/MR_Jukebox_Service/net"
binding="netTcpBinding"
bindingConfiguration=""
contract="MR_Jukebox_Service.IJukeboxService" />
</service>
</services>
</system.serviceModel>
In the same solution, I have a test application that I wish to connect to the netTcpBinding, I've right clicked on "Service References" and chosen "Add Service Reference...".
When I click on "Discover" it finds the service although says;
There was an error downloading 'http://localhost:8732/Design_Time_Addresses/MR_Jukebox_Service'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://localhost:8732/Design_Time_Addresses/MR_Jukebox_Service'.
There was no endpoint listening at http://localhost:8732/Design_Time_Addresses/MR_Jukebox_Service that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.
But I am also unable to see the netTcpBinding in order for me to create a service reference to it.
I was wondering whether anyone can see what I am doing wrong as its probably something rather simple, but due to my lack of experience with WCF haven't noticed.
Thanks for any help in advance.
Try changing your mex endpoint to this:
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
You were using your service's contract for the mex endpoint, which I don't believe will work.
You can set up a similar one for the NetTcpBinding:
<endpoint address="net.tcp://localhost:8523/Design_Time_Addresses/MR_Jukebox_Service/net/mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
I have been successful in getting the webHttpBinding to be accessible through a Java client and now I'm working on trying to get the netTcpBinding working.
Are you trying to get the netTcpBinding to work with a java client ? Because, netTcpBinding only works with a .net client.
NetTcpBinding is not designed for interop, it's designed for performance when both the server and client are .net

Configuring WCF Security (wsHttpBinding)

I have two websites hosted on the same IIS server. SiteA contains WCF services that need to be accessed by SiteB, as well as anything else that is authenticated on the domain.
The service is configured with a wsHttpBinding and thus I believe uses Windows security by default. Right now I can call the services from a console app running on my local machine, as well as from a web application running in the default Visual Studio web server, so I am taking that the authentication is working.
However, when SiteB tries to access the services, it fails with this error:
The caller was not authenticated by the service.
SiteB runs on the same machine than SiteA so I don't understand why it could not be authenticated. SiteB uses Forms Authentication and I mapped Anonymous access to a domain user.
Here are the config bits:
SiteA (service):
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="wcfServiceBehaviour" name="MyService">
<endpoint address="" binding="wsHttpBinding" contract="IServiceContract" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="wcfServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
SiteB (client):
<system.serviceModel>
<client>
<endpoint address="http://xxxxx/Services/xxService.svc"
binding="wsHttpBinding"
contract="IServiceContract" />
</client>
</system.serviceModel>
You are correct - wsHttpBinding configured in WCF will use Windows Authentication by default.
There is a suggestion here - WCF - changing endpoint address results in securityexception - that the Identity block will not work with Windows Authentication - try removing it.
When SiteB impersonates another user, does your code specify the impersonation level?
My guess is that your are not specifying a high enough level of impersonation. (Delegation is the highest, allowing SiteB to pass the permissions to a different service).
I suspect that fixing up the SiteB impersonation code will be enough to solve the problem.
If not, try passing the allowable impersonation level to the server:
<system.serviceModel>
<client>
<endpoint address="http://xxxxx/Services/xxService.svc"
binding="wsHttpBinding"
contract="IServiceContract"
behaviorConfiguration = "ImpersonationBehavior" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ImpersonationBehavior">
<clientCredentials>
<windows allowedImpersonationLevel = "Delegation" /> <!-- The highest level -->
</clientCredentials>
</behavior>
<endpointBehaviors>
</behaviors>
</system.serviceModel>
If you're using a self hosted site like me, the way to avoid this problem (as described above) is to stipulate on both the host and client side that the wsHttpBinding security mode = NONE.
When creating the binding, both on the client and the host, you can use this code:
Dim binding as System.ServiceModel.WSHttpBinding
binding= New System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None)
or
System.ServiceModel.WSHttpBinding binding
binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None);

Why does my WCF service not respond my baseAddress setting in web.config?

I'm trying to learn how to build RESTful services with WCF by recreating the project on this blog post by Anthony Steele. He uses the following XML in his config to setup the endpoint for the service.
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/greeter"/>
</baseAddresses>
</host>
However, when I try to do the same thing in my ASP.NET 3.5 web site's web.config, I am unable to navigate to my service. Here is the XML I'm using:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="GreeterBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="GreeterBehavior" name="Greeter">
<host>
<baseAddresses>
<add baseAddress="http://localhost:49268/TestREST/webapi/services/greeter"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="IGreeter">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
I would imagine my configuration would allow me to navigate to http://localhost:49268/TestREST/webapi/services/greeter and see my service. All I get is a resource not found message - am I missing something?
Edit: Part of my problem was my binding was wsHttpBinding. Using webHttpBinding allowed me to use the service correctly - except, the baseAddress config section still has no effect.
My hunch is that the service endpoint is not being created successfully.
In the service "name" attribute you are not including the FQN (Fully Qualified Name) of the service type. Secondarily, in the endpoint "contract" attribute you are also not including the FQN to the contract type.
On the other hand, this MAY be a port issue. In order to be sure, try running the WcfTestClient.exe that is included in the Visual Studio 2008 distribution. If you can connect to http://localhost:49268/TestREST/webapi/services/greeter/mex, then you know it is not a port issue.
Supposing that you can connect via MEX, then try exercising some of the methods, which would presumably be mapped to http://localhost:49268/TestREST/webapi/services/greeter.
If you are operating on server, see some valuable details about HttpCfg.exe here:
WCF ServiceHost basicHttpBinding 503 error
If you need more details on WcfTestClient, look for them here:
Is it possible to make the WcfTestClient work for custom transport channels?
Just In Case: copy the sample verbatim and verify that it works as defined, including the config file, before making the slightest deviation from it.