I created a WCF application that must be accessible on internet.
I deployed this application on a WS2008 R2 server with IIS. This server have a private IP but I configure NAT redirection on port 35000.
When I put the correct URI (with public IP) on a web browser, I can show the service page correctly but the link generated by IIS to show WSDL is not correct, I have the server name instead of public IP like this :
http://serverName:35000/ServiceName.svc?wsdl
instead of
http://publicIP:35000/ServiceName.svc?wsdl
so when I click on the link, the server name can't be resolve.
In my web.config file, I add an endpoint with the correct IP, and I also try to add an identity tag and DNS tag with the public IP but it doesn't work.
This is my web.config :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="myNamespace.ServiceName.svc">
<endpoint address="http://xxx.xxx.xxx.xxx:35000/myNamespace/ServiceName/" binding="wsHttpBinding" contract="myNamespace.IServiceName">
<identity>
<dns value="xxx.xxx.xxx.xxx" />
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
This is the end of WSDL :
<wsdl:service name="ServiceName">
<wsdl:port name="BasicHttpBinding_IServiceName" binding="tns:BasicHttpBinding_IServiceName">
<soap:address location="http://serverName:35000/ServiceName.svc"/>
</wsdl:port>
</wsdl:service>
I also try in IIS to add the public IP as hostname but I obtain an error.
Thanks for your help
The solution is to add the mex endpoint :
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
and it works perfectly...
Related
I've developed a wcf service with basichttpbinding. I've hosted the service on web server. There is a load balancer which exposes this service through https url. When i try to access the endpoint address exposed via load balancer it throws error in wcf test client - "The HTTP request was forbidden with client authentication scheme 'Anonymous'."
Below is the web.config configuration:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="testServiceBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceSecurityAudit auditLogLocation="Application" suppressAuditFailure="false"
serviceAuthorizationAuditLevel="SuccessOrFailure" messageAuthenticationAuditLevel="SuccessOrFailure" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="testServiceBehavior" name="TestService">
<endpoint address="" binding="basicHttpBinding"
contract="TestService.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Make sure to enable anonymous authentication in IIS:
If this value is set to Disable, the client needs to provide Windows identity information when calling.
I Created the WCF Service Library in MS Web Developer 2010 Express with ITestSerivce being the Service Contract and gaving following Web.config configuration. But im getting this error
:
Error: Cannot obtain Metadata from http://localhost:56016/TestService.svc
:
I dont understand why the url is http://localhost:56016 where in base address is http://localhost:8001
Can anybody help me with this issue.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="TestService">
<host>
<baseAddresses>
<add baseAddress ="http://localhost:8001/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="ITestService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!--Setting httpGetEnabled you can publish the metadata -->
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="SampleServiceBinding">
<security/>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
There are a few problems with the config above.
The service element has the name attibute which is not fully qualified name.
The endpoint element has the contract attribute value which is not fully qualified name.
A fully qualified name is as shown below:
MyWCFService.TestService (i.e. namespace.ServiceName)
If you are running the same on Cassini web server then right click on properties and under the web tab make sure that the "User Visual Studio Development Server" option is selected and the "Auto-assign Port" option is not selected. Rather select "Specific Port" and use 8001 to match your configuration
The <baseAddresses> configuration is only for self-hosted services + applications, and is not used by IIS / WAS.
Where you 'put' the .svc on your web server / site defines its url, unless you are using a feature such as file-less activation (article here)
Your IIS url will be something like
http://localhost:8001/MyApp/TestService.svc?wsdl
I'm not sure why WCF test client is defaulting to the wrong URL - just type in the correct one and it will cache it.
I created a WCF web service and created a new site in IIS (7). I created a new port (8002) for http requests. I can browse to the site and get the typical "You do not have permission to view this directory ..." so I know the site is working. However, I set my endpoint address to "http://1.1.1.1:8002" in my web.config (where 1.1.1.1 is replaced with my actual real IP address). when I browse to the service with http://1.1.1.1:8002/service.svc I get page cannot be found error. There is a service.svc in the root folder of the site. What is wrong with the setup?
Here is the web.config file if helpful (again, the 1.1.1.1 is replaced with my real IP address):
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicBinding">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WcfService.ServiceBehavior" name="WcfService.Service">
<endpoint address="http://1.1.1.1:8002" binding="basicHttpBinding" bindingConfiguration="BasicBinding" contract="WcfService.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService.ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
You cannot control the address of your service in configuration file when hosting in IIS. You can control only relative address of the endpoint - it is relative to .svc file.
So if you host the service in the site http://YourIP:8002 its address is http://YourIP:8002/Service.svc and the address element in the endpoint is relative to this address. But I expect you don't host the service directly in the site. You have some application in the site and the name of the application is part of the URL: http://YourIP:8002/YourApplicationName/Service.svc Actually every folder used to nest the service is part of the URL.
I have the simplest WCF service which works when hosted in IIS using basicHttp binding. It has one empty method called DoNothing which takes no parameters and returns a void
void DoNothing()
However I cannot get it to work when trying to host it in IIS using net.tcp.
I am assuming it is the configuration, as the same service code should work regardless of binding used.
I have enabled non-http activation. I am using a different port 12345 to avoid any clashes. The website and service is set up to use net.tcp binding.
The Net.Tcp ListenerAdaptor and Net.Tcp Port Sharing services are running
I can get the metadata to use WcfTestClient to test the service.
The error I get is
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:00:59.8597984'.
The inner exception is
An existing connection was forcibly closed by the remote host
I thing I have checked everything. I have tried calling it remotely and locally on the virtual machine
I can only think it is a simple config error or a security issue. The virtual machine is not in a domain. I have disabled the firewall completely on the virtual machine.
Has anyone had the same issue, and has a resolution. Or does someone have a very simple (full) example of how to host a net.tcp service in IIS, whih they could post
Here is my web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="PortSharingBinding" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="SimpleNetTcpService.Service">
<endpoint address="net.tcp://192.168.0.2:12345/SimpleNetTcpService/Service"
binding="netTcpBinding" bindingConfiguration="PortSharingBinding"
contract="SimpleNetTcpService.IService" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I found the issue. I just removed the address attribute from the service element
was
<service name="SimpleNetTcpService.Service">
<endpoint address="net.tcp://192.168.0.2:12345/SimpleNetTcpService/Service"
binding="netTcpBinding" bindingConfiguration="PortSharingBinding"
contract="SimpleNetTcpService.IService" />
now
<service name="SimpleNetTcpService.Service">
<endpoint
binding="netTcpBinding" bindingConfiguration="PortSharingBinding"
contract="SimpleNetTcpService.IService" />
Works fine now
I have started learning WCF and have created a few test http services successfully. Now, i was trying to create a self-hosted WCF service using net.pipe binding. Below is the configuration file for the service:-
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MEX" name="InProcService.MyService">
<endpoint address="MyService"
binding="netNamedPipeBinding" bindingConfiguration="" contract="InProcService.IMyService" />
<endpoint address="Mex" binding="mexNamedPipeBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/InProcService/" />
<add baseAddress="http://localhost:8001/InProcService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MEX" >
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Now in my host application, I am starting the service using:-
ServiceHost host = new ServiceHost(typeof(MyService));
host.Open();
Console.WriteLine("Service started");
host.Close();
The service starts correctly when this code is executed.
Now, when in my client application, I try to add the service reference to this running service, it is not able to find it. Is there something which I am not doing or doing incorrectly?
I would appreciate any help I can get on this.
Cheers,
Abhi.
The service is opened and closed after that. By the time you start the client the server is already closed. So Console.ReadKey() is required is requied before close.