Self hosted wcf service on azure vm windows server - c#

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

Related

How to configure client to catch local WCF requests in Fiddler?

I have simple client app (console application) and server app (WCF library project) using WCF. I want to see how WCF messages looks like in Fiddler.
I added following code to client's app.config:
<configuration>
<system.net>
<defaultProxy>
<proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://127.0.0.1:8888" />
</defaultProxy>
</system.net>
My Fiddler shows all connections from browsers except one having word "vshub" in url, but there are no connections between WCF client/server apps displayed. How to configure it?
UPDATE1:
My WCF service library (server application) is configured in following way:
<system.serviceModel>
<services>
<service name="WcfServer.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServer/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="WcfServer.IService1">
<!--
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>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="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>
you have nothing to do in the client config and you can remove your proxy settings. Fiddler will work if you do not use "localhost" and replace it with "MyMachineName"
Local requests aren't catched by Fiddler. Fiddler only catches requests that actually go over the wire. Local requests are shortcutted by Windows.
There is an old post with some alternatives, although I don't know how actual that list is.

How to resolve AddressAccessDeniedException in WCFhost

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.

WCF service works locally on App Server but can reach it from Web Server

I have WCF service works locally on App Server http://appserver.org/UserManagementService.svc?wsdl and https://localhost/UserManagementService.svc meaning that it will show me the XML defenition of the WSDL, but can NOT reach http://appserver.org/UserManagementService.svc?wsdl or http://appserver.org/UserManagementService.svc from Web Server, I also cant reach those address's from my development machine, inside VS or directly in a browser. I get the error below when I try:
There was an error downloading 'https://appserver.org/UserManagementService.svc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'https://appserver.org/UserManagementService.svc'.
There was no endpoint listening at https://prod-uibenapps.sces.org/UserManagementService.svc 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.
This is the web.config for the service application hosting the services in IIS
<system.serviceModel>
<services>
<service name="WedWiaPortal.SCAL">
<host>
<baseAddresses>
<!--<add baseAddress="http://localhost/usermanagementservice"/>-->
<add baseAddress="http://prod-uibenapps.sces.org/UserManagementService.svc"></add>
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
contract="WedWiaPortal.SCAL.IUserManagementService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false 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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Thank you in advance for any help, have been banging my head a couple of days.

Failed to invoke the service. Possible causes: The service is offline or inaccessible while Invoking

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>

WCF with discovery fails with socket not valid in its context on XP?

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.

Categories