Unable to configure WCF service to be consumed by silverlight client - wcf

I am trying hard to develop a duplex wcf service to be consumed by silverlight clients. Now for adventure sake, I decided to use nettcpbinding. I understand that the concept of PolicyServer to be running on port 943 is obselete now and it should be served from root of the service.
given Below is config section for the service
<behaviors>
<serviceBehaviors>
<behavior name="WcfServer.WcfServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="CrossDomainServiceBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WcfServer.WcfServiceBehavior"
name="WcfServer.MainService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="TCPBinding" contract="WCFWebFrontCommunication.IMainService">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="CrossDomainServiceBehavior" contract="WCFWebFrontCommunication.IClientAccessPolicy" />
<host>
<baseAddresses>
<!--<add baseAddress= "http://192.168.0.101:943/WcfServer/MainService" />-->
<!--<add baseAddress= "http://localhost:943/WcfServer/MainService" />-->
<add baseAddress= "net.tcp://localhost:4502/WcfServer/MainService" />
<add baseAddress="http://localhost:4502"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
now at runtime I get an exception HTTP could not register URL http://+:4502/ because TCP port 4502 is being used by another application. when Open Method is called.
Am I doing something silly here .., although http exception was there with basicHttpBinding as well
As Troubleshooting:
checked for open port using Netstat -aon
There were some post regarding HTTP configuration followed them nothing happened
Thanks for reading.

You're trying to host a clientaccesspolicy.xml file over HTTP, and use net.tcp on the same port number, that's not going to work. While both of these protocols build on TCP/IP, they are incompatible.
As far as I understand (see also this article), port 943 is still used for this type of thing.

Related

Service Reference Error - netTcpBinding

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/.

How to run WCF service on a specific port

I have a .Net 4.0 WCF service running on IIS. I have not specified a port so assume it is running on port 80. I need to install my service on a server where port 80 is already being used and the network guy had asked me to change my service to run on port 443. How do I do this? I'm guessing it can be configured in app.config but I can't find an article that shows me how.
Here is my current app.config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
I am assuming you are running your services on net.tcp protocols.
1) Edit your bindings (right click Default Web Site select Edit Bindings
2) Server Side
<service name="YouServiceNameSpace.YourService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="YourBinding" contract="YourContract" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" />
</service>
3) Client Side
<endpoint address="net.tcp://YourHost:443/YourServiceDirecotry/YourService.svc"
behaviorConfiguration="YourBehavior" binding="netTcpBinding"
bindingConfiguration="YourTcpBinding" contract="YourContract"
name="YourContractName" />
We can do it using the .csproj file of the WCF project(in case of using VS).Just change the value of this xml tag in your corresponding file:
To Run the service at port number 60000 ,
<DevelopmentServerPort>60000</DevelopmentServerPort>
Normally you should have a services node with at least one service node and each having endpoints, where you can specify the port. See more at: http://msdn.microsoft.com/en-us/library/ms733932.aspx
For example:
<services>
<service name="MyNamespace.myServiceType">
<endpoint
address="net.tcp://0.0.0.0:8000" binding="basicHttpBinding"
bindingConfiguration="myBindingConfiguration1"
contract="MyContract" />
</service>
</services>
Specify the port in the address of the endpoint. See the 'Defining Endpoint Addresses in Code' section in this article for more details.

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

Extending timeout and message size in WCF service generated by Biztalk 2006 R2

I'm generating WCF service using Biztalk. The code I get is this:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviorConfiguration">
<serviceDebug httpHelpPageEnabled="true" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="false" />
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" externalMetadataLocation="" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<!-- Note: the service name must match the configuration name for the service implementation. -->
<service name="Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkServiceInstance" behaviorConfiguration="ServiceBehaviorConfiguration">
<endpoint name="HttpMexEndpoint" address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<!--<endpoint name="HttpsMexEndpoint" address="mex" binding="mexHttpsBinding" bindingConfiguration="" contract="IMetadataExchange" />-->
</service>
</services>
</system.serviceModel>
Maybe it's not the most beautifull configuration, but it works. The problem is I don't know how to modify timeouts and message max size, because it has only mex endpoint. I'm surprised how this works at all with just mex endpoint.
So two questions are:
Why does this works at all?
What should I add to extend timeouts and message size?
I seem to recall the reason those settings aren't in the config file is because the binding configuration is stored in the receive location / send port settings in biztalk itself. So the way to set them is to change them from the receive location adapter configuration.

WCF AJAX: scripting across ports

using ASP.net, C#, IIS, jQuery
I have a wcf service running in iis on port 2515.
the demo i created for this project works fine and i can utilize the service.
I have another project running on port 2971.
I want this project to consume the wcf service via javascript but am getting a "method not allowed error".
Is this a cross-site scripting issue? I'm thinkin no since both projects are on the same domain but at different port numbers.
any help would be much appreciated.
<serviceBehaviors>
<behavior name = "MetadataBehavior">
<serviceMetadata httpGetEnabled = "true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SandwichServices.CostServiceAspNetAjaxBehavior" >
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="SandwichServices.CostService" behaviorConfiguration="MetadataBehavior">
<endpoint address="" behaviorConfiguration="SandwichServices.CostServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="SandwichServices.CostService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:2152/"/>
</baseAddresses>
If you're using XHR, the port is taken into account in the same-origin policy. You can't do requests across different ports - think of it as a part of the domain name.