WCF endpoints on production server - c#

I have made a simple WCF service, and it´s working like a charm in my developer environment. But now I'm moving it to my test server (AZURE) and i can´t get the endpoint address correct. The IIS is up and running, and the service is working locally on the test server.
When I try to test the service in WCF Test client, I receive an error when I try to invoke that the endpoint is incorrect:
There was no endpoint listening at mypathattestserver/Service1.svc
that could accept the message. This is often caused by an incorrect
address or SOAP action. See InnerException, if present, for more
details.
This is my web.config:
<services>
<service behaviorConfiguration="Test.Service1Behavior" name="Test.tfn">
<endpoint address="" binding="basicHttpBinding" contract="Test.IService1">
<identity>
<dns value="http://mypathattestserver.cloudapp.net/service1.svc"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Test.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>

I would suggest the following steps:
Check the service with another client. SoapUI is a very good web service client. If the service responds to SoapUI then the problem is on your client
If the server is fine and the problem is at your client, remove the reference looking at the specific server and add it again.
Finally, check your firewalls. If the system plays fine by having the client and the server on the same machine, the firewalls could be a problem when the server is located on another machine.
Hope I helped!

Related

How to use IIS WCF Host Service over internet when server is behind NAT

I've waste xx hours for finding solution, but without success :(
I have IIS Server behind NAT, there is a WCF Service Host installed (on IIS).
Localy and over LAN Communication client-WcfService working property, but when i try to add service reference (over internet) to my wcf service host - in visual studio, i have an issue as below:
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved:
I have redirected on my router port WAN to port Lan of my WCF Sercice. Its working property because when i connect over internet to http://[...] .svc file in browser i can see proper site.
my web.config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehavior" name="KSPDJOBService.KSPDJOBService">
<endpoint address="" binding="wsHttpBinding" contract="KSPDJOBService.IKSPDJOBService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/KSPDJOBService" />
</baseAddresses>
</host>
</service>
</services>
Any Ideas how to resolve my problem? i would be very thanksful for any tips.
Thanks.
Sorry for my english :)
I resolved this issue.
1st issue was: in port forwarding router has forwarding WAN port X to local port Y
2nd issue was: in svc/wsdl i had local url (thats why i had HTTP 400 error when trying to connect from internet)
SOLVED:
1st. So i've made forwarding WAN_port: Y to LAN_port: Y (the same ports)
2nd. I added in IIS Site - Binding hostname as WAN_domain_name.
Credits to : https://gavinmckay.wordpress.com/2009/03/24/howto-fix-wcf-host-name-on-iis

add service reference only works with localhost wcf service

I am trying to host a svc service in my web application and I am trying to connect to it with a simple client application.
When the host is hosted in my own computer and solution, and I run the web application locally, everything works fine, meaning that I can add the reference to the service using add service reference in my client solution with http://localhost:6543/Hello.svc as the address and when I navigate to the service's url, it shows me the service's information as it should.
But when I publish my website, and I try to add the reference to my service using add service reference with http://myserver.com/Hello.svc as the address, i get the error message bleow:
There was an error downloading
'http://myserver.com/Hello.svc/_vti_bin/ListData.svc/$metadata'. The
request failed with HTTP status 404: Not Found. Metadata contains a
reference that cannot be resolved: 'http://myserverc.com/Hello.svc'.
The remote server returned an unexpected response: (405) Method Not
Allowed. The remote server returned an error: (405) Method Not
Allowed. If the service is defined in the current solution, try
building the solution and adding the service reference again.
and oddly when I navigate to myserver.com/Hello.svc, the browser starts to download the Hello.svc file instead of showing the service's details and information.
this is my website's web.config file:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WithDebug">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="HelloWorldService.HelloService" behaviorConfiguration="WithDebug">
<host>
<baseAddresses>
<add baseAddress="http://myserver/Hello.svc"/>
</baseAddresses>
</host>
<endpoint
address=""
binding="webHttpBinding" bindingConfiguration="crossDomain"
contract="HelloWorldService.IHelloWorld" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
I think I am missing something big here, but since I am new to WCF, I don't know what it is.Any help would be appreciated and I am more than happy to issue more details about my project if needed.
Thanks in advance
You need to run ServiceModel registration tool
"This command-line tool provides the ability to manage the registration of WCF and WF components on a single machine. Under normal circumstances you should not need to use this tool as WCF and WF components are configured when installed. But if you are experiencing problems with service activation, you can try to register the components using this tool."

Connect to WCF service with name instead of IP

Hey I have made an WCF service and would like to be able to connect to it with an dns I set?
as it is now I have to conncet to the baseaddress via the computers ip.
and the DHCP sometimes gives new ip and then the clients have to know the new ip and so on... you hopefully get it :)
so how can I make it connect via a name instead? and like have localhost in baseaddress
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="metaAndErrors"
name="VenatoWCF.WCFService">
<endpoint address="http://localhost:8732/End"
binding="basicHttpBinding"
contract="VenatoWCF.IService">
<identity>
<dns value="dendei"/>
</identity>
</endpoint>
<endpoint address="http://localhost:8732/mex"
binding="mexHttpBinding"
contract="IMetadataExchange">
<identity>
<dns value="dendei"/>
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/VenatoWCFconsole/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metaAndErrors">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
been trying something like this but no luck xD, i would like to connect from client side with "http://dendei:8732/VenatoWCFconsole/"
so even if my ip changes the clients dont have to make changes to connect to me
thank you for answers!
no matter what, something will have to supply the endpoint address (i.e. ip/port). If that value is set to change frequently, i would set a port forwarder in between your client and service.
http://en.wikipedia.org/wiki/Port_forwarding
As i understood you don't have a static ip address and try to overcame this by having a static DNS name, in my opinion this would not work because you should have a static ip address and than assign to it a static DNS name, then try to connect.
I think this is a scenario that should "just work". Your service base address in the service config should be able to use localhost as you illustrated. In your client-side config you should configure your endpoint address using the DNS name for the host where the service is running.
Check that the client machine can ping the service machine using the DNS name. If that resolves ok, there is no reason why WCF shouldn't connect. You should not have to change any config when the DHCP server decides to allocate a new IP address, so long as clients can still resolve the DNS name to the new IP address.
For example, in your client config...
<client>
<endpoint address="http://dendei:8732/VenatoWCFconsole/End"
binding="basicHttpBinding" bindingConfiguration="sameBindingConfigYouAlreadyUse"
contract="Whatever.YourContractNameIs" name="YourEndpointName" />
</client>
Update: I just spotted there's a problem in your service config above. In the service endpoint config you should specify address as just the additional part of the URI that will get appended to the base-address. So, instead of address="http://localhost:8732/End", you just need address="End".

WCF Client does not consider Host Address

I have the following configuration file for WCF service. There is a host defined in the config. Still, when I print the service address from the client, it does not know about the host. The printed result is:
http://localhost:3187/Service1.svc/MyFolder
Why doesn’t it take into account the host name? What modification do we need to do for it?
Note: I am running from VS 2010 for running service and client website.
Service1Client myClientService = new Service1Client();
Response.Write(myClientService.Endpoint.Address);
Client Configuration (Autogenerated by Visual Studio)
<client>
<endpoint address="http://localhost:3187/Service1.svc/MyFolder"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="MyWCFReference.IService1" name="WSHttpBinding_IService1">
<identity>
<userPrincipalName value="U16990#ustr.com" />
</identity>
</endpoint>
</client>
The server side configuration is:
<services>
<!--MyService-->
<service name="MyWCFServiceApplication.MyService"
behaviorConfiguration="WeatherServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/ServiceModelSamples/FreeServiceWorld"/>
</baseAddresses>
</host>
<endpoint address="MyFolder"
binding="wsHttpBinding"
contract="MyWCFServiceApplication.IService1" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WeatherServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
When a WCF service is hosted in an ASP.NET process, through either IIS or the ASP.NET Development Server (a.k.a Cassini), the baseAddresses setting in the service's configuration file is ignored since the service will always be reachable through the URL of the SVC file.
The URL you're seeing on the client is therefore correct:
http://localhost:3187/Service1.svc/MyFolder
As you can see, the base address of the service becomes the URL of the SVC file on the web server.
You're talking about a WCF client - yet, the config you posted only contains config for a service (the server side) ... (the <services> section).
I can't see any client configuration in what you posted - there ought to be a <client> section in your config somewhere

calling WCF client function doesn't work on IIS

I made a service using the WCF discovery. Everything works fine when it is deployed on a specific port (using VS2010 debug), but when I try to deploy it to IIS it finds the service but can't run any of the methods.
This is the code:
DiscoveryClient discoverclient = new DiscoveryClient(new UdpDiscoveryEndpoint());
FindResponse response = discoverclient.Find(new FindCriteria(typeof(IService)));
EndpointAddress address = response.Endpoints[0].Address;
ServiceClient client = new ServiceClient(new BasicHttpBinding(), address);
Console.WriteLine(client.getMsg()); //some test function
Console.ReadKey();
When tring to run the client.getMsg() method I get the following error:
EndpointNotFoundException:
There was no endpoint listening at
http://computerName.domain/services/Service.svc that could accept the
message. This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details.
But I got the address, meaning it found it. And if I use the debug deployer (not to iis) I find it in http://localhost:port/services/Service.svc and it runs perfectly fine. How can I have it deployed to iis with no problems?
OS : win7 64 bit
config file :
<services>
<service behaviorConfiguration="RemoteDeploy.Service1Behavior"
name="RemoteDeploy.Service">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
contract="RemoteDeploy.IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint name="udpDiscoveryEpt" kind="udpDiscoveryEndpoint" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RemoteDeploy.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceDiscovery>
</serviceDiscovery>
</behavior>
</serviceBehaviors>
</behaviors>
First try to GET http://computerName.domain/services/Service.svc in your browser - either you get an error or service description..

Categories

Resources