I created a simple WCF service and hosted in a console application.
After configuring all the endpoints I got an exception as below.
Below in my configuration file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="HelloService.HelloService" behaviorConfiguration="mexBehaviour">
<endpoint address="HelloService" contract="HelloService.IHelloService" binding="basicHttpBinding"></endpoint>
<endpoint address="HelloService" contract="HelloService.IHelloService" binding="netTcpBinding"></endpoint>
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8081/"/>
<add baseAddress="net.tcp://localhost:8090/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Help me how to resolve this error?
The error occurs because of permission problem in your operating system.
Your operating system does not allow WCF service on a specified port.
All you need to do is to create an exception for that port.
Below is the procedure:
Click Start
Run cmd prompt as an administrator
type netsh.exe and press enter
type http add urlacl url=http://+:8081/Service/ user=administrator and press enter.
Here you need to observe three points
8081: is your port on which you need access. Replace it with your own port number.
Service: this is your sesrvice name. Ex: MyWeatherService
administrator: you have to give access to the ser you want on your computer. In my case I gave access to adminitrator. Ex: you can give access to the puppy if there is an user named puppy on your machine.
Check first if the WCF service can user port 80
run your application as administrator, it will resolve the issue.
Related
I have wcf service with udp binding (new in WCF 4.5) and I'm trying to host it on Windows Server 2012 on Azure.
I did endpoint mapping on Azure for port I need (39901; it works for HTTP:80, I can see IIS website) and I allowed all traffic in firewall for this port.
But I still can't get wsdl in web browser.
Here is app.config for console app:
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="12" maxConcurrentInstances="56" maxConcurrentSessions="12" />
<useRequestHeadersForMetadataAddress></useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="ServerService.UdpServiceAlpha">
<endpoint address="soap.udp://localhost:8091" binding="udpBinding" contract="ServerService.IUdpServiceAlpha" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:39901/SelfServerHost/" />
</baseAddresses>
</host>
</service>
</services>
<protocolMapping>
<add binding="udpBinding" scheme="soap.udp" />
</protocolMapping>
<bindings>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
For localhost everything works fine... I'm new in this (azure, windows server deployment) and I tried a lot of ideas here on stackoverflow or anywhere else. But still not working.
Any idea?
EDIT1:
<services>
<service name="ServerService.UdpServiceAlpha" behaviorConfiguration="UdpServiceAlpha.Behavior">
<endpoint address="/" binding="udpBinding" contract="ServerService.IUdpServiceAlpha"/>
<endpoint address="/" binding="webHttpBinding" contract="ServerService.IUdpServiceAlpha"/>
<host>
<baseAddresses>
<add baseAddress="http://xxx.cloudapp.net:39901/SelfServerHost/" />
<add baseAddress="soap.udp://xxx.cloudapp.net:39901/SelfServerHost/" />
</baseAddresses>
</host>
</service>
</services>
Try changing the Azure VM Endpoint public port from 39901 to 443!
A hell lot of sys-admins and ISPs block all outgoing ports, and only allow few (outgoing port white listing). Port 80 and 443 are usually never blocked because it is usually HTTP traffic.
Change only the public port for the VM Endpoint. Leave the private port as is - 39901.
Your configuration file seems to have a few issues:
The service behavior is missing a name:
<serviceBehaviors>
<behavior name="my.service.behavior"> ...
The service needs to reflect the binding configuration
<service name="ServerService.UdpServiceAlpha" behaviorConfiguration=" my.service.behavior ">
Yeah, finally... got the solution for this. My friend (network big boss :) ) told me how port communication works... Idea was simple: "check once again server and client firewall ports", and here is that point "client firewall".
I allowed only server firewall ports, but there should be allowed communication for client. Added TCP/UDP Outbound rule in client PC and it works magically.
... and for UDP I needed to change TTL (default is 1).
I created the self hosted WCF service with C# application. I want to send messages to C# application from remote php server. How can i perform this function?
<?xml versio="1.0"?>
<configuration><system.serviceModel>
<services>
<service name="MyMathServiceLib.MyMathService" behaviorConfiguration="myMathServiceBehave">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9001/MyMathService"/>
<add baseAddress="net.tcp://localhost:9002/MyMathService"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:9001/MyMathService" binding="basicHttpBinding" contract="MyMathServiceLib.IMyMathService"/>
<endpoint address="net.tcp://localhost:9002/MyMathService" binding="netTcpBinding" contract="MyMathServiceLib.IMyMathService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myMathServiceBehave">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
This is my app.config file(ref: http://www.codeproject.com/Articles/650869/Creating-a-Self-Hosted-WCF-Service)
My aim is to send message from php server to c# application
Follow the simple steps:
In your visual studio folder, you should see WCF Client.
Add your WCF URL to this client (http://localhost:9001/MyMathService in your case). Fill example data in the request and click on "XML".
Copy the XML and put it in a variable in PHP. Instead of your dummy values you put in the previous step, put proper PHP variables.
Enable PHP CURL. POST this variable to the WCF service.
I have my service configured as below:
<system.serviceModel>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="MyServiceTypeBehaviors">
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:808/service" />
</baseAddresses>
</host>
<endpoint address="net.tcp://127.0.0.1:808/service/"
binding="netTcpBinding"
contract="WcfService1.IService1"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<protocolMapping>
<add scheme="net.tcp" binding="netTcpBinding"/>
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyEndpointBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
and the client as:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService1" sendTimeout="00:05:00" />
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://127.0.0.1/service/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="IService1"
name="NetTcpBinding_IService1">
<identity>
<servicePrincipalName value="host/MachineName" />
</identity>
</endpoint>
</client>
</system.serviceModel>
When using WCFTestClient or SVCutil, I am able to discover and access the servie and generate proxy or stubs.
But when I want to invoke any of the methods getting following error:
Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:04:59.9980468'.
Set the following value inside the endpoint block
<identity>
<dns value ="localhost"/>
</identity>
Maybe not the answer you are looking for, but for development on the local machine I always use an HTTP endpoint. I find Net.TCP will only play nice when it is hosted on a server in IIS.
It is easy enough to add the NET.TCP endpoints once you deploy to an IIS server. Note: that the base address no longer has any affect as that is set in IIS. To test the new endpoints it is best to start by opening the service in a browser while remoted into the server, that way you get the best error messages.
If i understand correctly you are trying to select the endpoint when creating the service reference? Thats now how it works.
If you create your service reference using 127.0.0.1/service/Service1.svc
You should see in your config file something like the following. (When I create my service endpoints I always name them with the protocol as a suffix.
<endpoint address="http://servername:8090/servername/servername.svc/Business"
binding="basicHttpBinding" bindingConfiguration="BusinessHTTP"
contract="servername.IService" name="BusinessHTTP" />
<endpoint address="net.tcp://servername:8030/Service/Service.svc/Business"
binding="netTcpBinding" bindingConfiguration="BusinessTCP"
contract="servername.IService" name="BusinessTCP" />
then in your code you can choose which endpoint to use.
Dim svc as New SeviceReferenceName.BusinessClient("BusinessTCP")"
I have faced the same issue. It was the issue of port address of EndpointAddress. In Visual studio port address of your file (e.g. Service1.svc) and port address of your wcf project must be the same which you gives into EndpointAddress. Let me describe you this solution in detail which worked for me.
There are two steps to check the port addresses.
In your WCF Project right click to your Service file (e.g. Service1.svc) -> than select View in browser now in your browser you have url like http://localhost:61122/Service1.svc so now note down your port address as a 61122
Right click your wcf project -> than select Properties -> go to the Web Tab -> Now in Servers section -> select Use Visual Studio Development Server -> select Specific Port and give the port address which we have earlier find from our Service1.svc service. That is (61122).
Earlier, I had a different port address. After specifying the port address properly, which I got from the first step, EndpointAddress 61122, my problem was solved.
I hope this might be solved your issue.
NetTcp binding is secured by default.In the security authentication process between client and service,WCF ensures that the identity of service matches the values of this element. Therefore service need to be configured with :
<identity>
<dns value ="localhost"/>
</identity>
I'm trying to use WCF's discovery mechanism in .NET 4.0. It works on Windows 7 but fails on an XP machine with a socket exception saying that "the requested address is not valid in its context" (the endpoint is soap.udp://239.255.255.250:3702).
Is the Windows 7 vs XP a red herring? netstat doesn't seem to show any conflicts. What am I missing here?
I've created a simplified test service that shows the problem using the following config:
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata/>
<serviceDiscovery />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<endpointDiscovery />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="HelloWorldService">
<host>
<baseAddresses>
<add baseAddress="http://localhost/Demo"/>
</baseAddresses>
</host>
<endpoint kind="mexEndpoint" />
<endpoint kind="udpDiscoveryEndpoint" />
<endpoint contract="Test.IHelloWorld"
address="/Hello"
binding="basicHttpBinding" />
</service>
</services>
</system.serviceModel>
</configuration>
There is an issue logged on Microsoft Connect. Unfortunately there is currently no workaround and Microsoft response is
The exception you are mentioning is
normally hit when trying to bind the
socket to an IP address that isn't
valid. Can you please check this and
if possible try on a machine with a
different OS. There are currently no
known limitations of the WCF Discovery
feature on XP.
Is the XP machine behind a firewall or router? To be specific, does the address 239.255.255.250 really belong to the XP machine, or does it actually use a NAT address? Try running ipconfig to see what it thinks it has.
i have a few questions about the below config file:
<system.serviceModel>
<bindings />
<services>
<service behaviorConfiguration="WcfReporting.Service1Behavior"
name="WcfReporting.Service1">
<endpoint address=""
binding="basicHttpBinding" bindingConfiguration=""
contract="WcfReporting.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5050/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfReporting.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>
</system.serviceModel>
Why when I hit F5 to restart the service, the service starts with this URL http://localhost:2752/ ... why not 5050 as I specified in baseAddresses.
How how can I add another endpoint. I tried with endpoint address="/Address2" binding="basicHttpBinding" contract="WcfReporting.IService1" />
should I how be able to access the service, not only with http://localhost/VirtualDir/ but also with http://localhost/VirtualDir/address2 or how does it work?
If you're hosting in Cassini from within Visual Studio 2005 or later, you can specify the port using Project/Properties/Web/Use Visual Studio Development Server/Specific Port.
By default the port will be auto-assigned - which isn't very helpful for Web Services as your clients will probably want to be using a fixed URL.
You don't need to specify <baseAddresses> in the config file when hosting in IIS or Cassini - the base URL is provided by the web server. The <baseAddresses> element is used when self-hosting.
How how can I add another endpoint. I
tried with endpoint
address="/Address2"
binding="basicHttpBinding"
contract="WcfReporting.IService1" />
The addresses you specify in this endpoint need to be local and relative - e.g. just specify
<endpoint address="Address2"
binding="basicHttpBinding"
contract="WcfReporting.IService1" />
and this will create an endpoint at the complete address of
net.tcp://localhost:5050/Address2
But as Darin has already pointed out - if you use IIS / WAS to host your service, the virtual directory where your *.svc file resides will take precedence and the base addresses specified will be ignored. In order to really use the base addresses, you'll need to self-host the service in a console app or Windows service.
Marc
If you use a web server (such as Cassini or IIS) to host your WCF service the base address will be provided from this server. Also note that you cannot use TCP bindings over HTTP. If you want to be able to set the base address property you need to host the service yourself (for example in NT service, console or windows application).