Referencing a Wcf Tcp service from within the same solution - wcf

I am going through the walkthrough "How to: Use netTcpBinding with Windows Authentication and Transport Security in WCF Calling from Windows Forms"
http://msdn.microsoft.com/en-us/library/ff647180.aspx
When I get to "Step 7: Create a Test Client Application" and substep 5: "5.In the Add Service Reference dialog box, set the Service URI: to net.tcp://localhost:8523/WCFTestService and then click Go"
I get "The URI prefix is not recognized. Metadata contains a reference that cannot be resolved".
It's as if the "Add Service Reference" doesn't recognize the "net.tcp" binding.
I'm on Windows 7 x64 using Visual Studio 2012 and my project is targeting x86 and Framework 4.5.
I found this thread
An error in the MSDN walk-through - "How to: Host WCF in a Windows Service Using TCP"
But they didn't have a problem when the client was in the same solution. I am.
Service Config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Publisher.MyServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="POC_WcfTcpSubscribePublishService.Publisher">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
name="NetTcpBindingEndpoint" contract="POC_WcfTcpSubscribePublishService.IPublisher">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="MexTcpBindingEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/WcfTcpSubscribePublish" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
any pointers are welcome.

The service must be running before you can add a reference to it.
You can run the service project separately from the context menu within Solution Explorer.

You have a service behavior: Publisher.MyServiceBehavior
But you don't apply that service behavior to your service. After service name="..." do this:
behaviorConfiguration="Publisher.MyServiceBehavior"

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 HTTP Error 404.17 - Not Found The requested content appears to be script and will not be served by the static file handler

I have made various attempts to resolve 404.17 issue for WCF but none of them worked
Development Environment VS 2008 Team System, .NET Framework 3.5, OS Windows 7.0, IIS Application pool v2.0 classic.
I installed C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ ServiceModelReg
I enabled Windows Communication HTTP Activation using Turn windows feature on
Handler Mappings in IIS
svc-ISAPI-2.0 *.svc Enabled Unspecified IsapiModule inherited
svc-ISAPI-4.0_32bit *.svc Enabled Unspecified IsapiModule inherited
svc-ISAPI-4.0_64bit *.svc Enabled Unspecified IsapiModule inherited
I cannot change the AppPool to integrated mode becuase Application does not work without classic mode, I have asmx webservices and they all are accessible. Its WCF which is causing issue. Could anyone help me how to resolve this 404.17 issue
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Solution1.WebApp.CallMonitorServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="Solution1.WebApp.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="Solution1.WebApp.CallMonitorServiceBehavior"
name="Solution1.WebApp.CallMonitorService">
<endpoint address="" binding="wsHttpBinding" contract="Solution1.WebApp.ICallMonitorService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="Solution1.WebApp.Service1Behavior"
name="Solution1.WebApp.Service1">
<endpoint address="" binding="wsHttpBinding" contract="Solution1.WebApp.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Try activating WCF service from windows Features. Goto "Control Panel\Programs\Programs and Features" and click "Turn Windows features on or off" and check wcf services as shown in pic attached.
Try to register WCF to IIS
Navigate to "C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation"
and execute
servicemodelreg -i
to install them

Role of baseAddress while configurting WCF Service EndPoint

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.

Can't add service reference to net tcp wcf service

I have a WCF service hosted on my local machine as windows service. Now I'm trying to add a service reference in the client (again on my local dev machine) but I'm getting an error
Metadata contains a reference that cannot be resolved:
'net.tcp://localhost:8523/Service1'. Could not connect to
net.tcp://localhost:8523/Service1. The connection attempt lasted for a
time span of 00:00:02.0011145. TCP error code 10061: No connection
could be made because the target machine actively refused it
I checked that the Windows firewall doesn't block port 8523. I even created a new rule in Windows firewall to allow run 8523 port. But when I'm running netstat -sp tcp I can't seem to find port 8523. But I can see Serice1 service's state is set to START in Services. This is the config files
Service Library
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<endpoint
address=""
binding="netTcpBinding" bindingConfiguration=""
contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/Service1" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Config in the windows service project looks identical.
Michael, this is a net.tcp binding that I typically use for a WCF service.
<bindings>
<netTcpBinding>
<binding name="TcpBinding"
receiveTimeout="Infinite"
sendTimeout="Infinite"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<reliableSession inactivityTimeout="Infinite"/>
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
Try to add it to your configuration:
<service name="WcfServiceLibrary1.Service1">
<endpoint
address=""
binding="netTcpBinding" bindingConfiguration="TcpBinding"
contract="WcfServiceLibrary1.IService1">
...
Also, my services are running under ServiceAccount.LocalSystem.
Check
netstat -ap tcp
if the service is listening.
EDIT: my Service class below. Note that the current directory of the windows service is set programatically to the BaseDirectory, i.e. the directory of the executable.
public class Service : ServiceBase
{
public static void Main()
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
ServiceBase.Run(new Service());
}
...
}
You've specified a behavior but haven't given it a name. Give the behavior a name and point to it using behaviorConfiguration in your service.
<service name="WcfServiceLibrary1.Service1" behaviorConfiguration="svc1behavior">
...
<serviceBehaviors>
<behavior name="svc1behavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
Check that Net.Tcp listener adapter service is running (although if it works while hosting the service in console application, it should be running).
To find the port your service is using,
Open Task Manager
Select View -> Select Columns -> Check PID -> OK
Find your service process name, note the PID
Run the followind command from the command prompt: netstat -ano | findstr *PID*
Had the same issue. After a lot of troubleshooting I found out I was missing a reference to the service in Web.config in the service project, so I added this to Web.config:
<system.serviceModel>
<services>
<service name="serviceName" behaviorConfiguration="BasicServiceBehavior" >
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicServiceBasicHttpBinding" contract="(I<nameofservice>)"/>
</service>
</services>
</system.serviceModel>
After this a rebuilt the solution (which created the interface) and republished. Then I could finally add a service reference from my other project.

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