Use URL to call wcf service instead of ip or localhost - c#

I hosted my WCF service on one static IP but when net disconnected then dynamic IP of system changes so my service stop working.
Now what I want to do is instead of using IP address or localhost I want to call service using URL.
This is my web.con file code for
<system.serviceModel>
<services>
<service name="abc.bca" behaviorConfiguration="mexendpoint">
<endpoint address="" binding="basicHttpBinding" contract="abc.Ibca">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/bca.svc" />
</baseAddresses>
</host>
</service>
</services>
And this is how I define an IP address for calling through mobile application suppose that below is my static IP.
117.87.21.12
So instead of call static IP can I redirect it to any URL like techit#.com

The issue is more related to Domain Name System. Generally, we could call the service with the computer name.
http://myserverhostname:xxx/service.svc
If we want to add the custom domain name, we should have an understanding on the DNS system,
https://en.wikipedia.org/wiki/Domain_Name_System
https://learn.microsoft.com/en-us/windows-server/identity/ad-ds/plan/reviewing-dns-concepts
For example, we want to access the computer with a bespoke name, we should ensure it located in the right dns name since the Domain Name System is recursively analyzed.
One more thing I want to share with you is the local “Hosts” file will be used preferentially when the domain name is resolved. Therefore, we could achieve it by add an entry to the file ( located in the System32/drivers/etc/hosts file). You could refer to the below link.
https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
Feel free to let me know if there is anything I can help with.

Related

WCF Web Service not deploying on localhost ... web.config ... endpoints

Trying to deploy a super barebones WCF Web Service and test it locally. I'm getting an error:
Could not find a base address that matches scheme https for the endpoint
with binding BasicHttpBinding. Registered base address schemes are [http].
I'll include my endpoint tags from the web.config file here:
<services>
<service name="Company.PrototypeWebService.PrototypeWebService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHTTPBinding" contract="Company.PrototypeWebService.ServiceContracts.IPrototypeWebService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
Is there something I'm missing here? I'm new to web service development.
This is because your base address is Http, but I see that your metadata endpoint uses https, which is the cause of the error,modify your Service:
<services>
<service name="Company.PrototypeWebService.PrototypeWebService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHTTPBinding" contract="Company.PrototypeWebService.ServiceContracts.IPrototypeWebService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
Modify mexHttpsBinding to mexHttpBinding.
If you want to use https binding, you need to configure the SSL certificate on the server. Normally, it is more convenient to use https in IIS.
UPDATE
If hosted in IIS, we need to create the following WCF project:
The directory of this project looks like this:
We can deploy the project directly to IIS, set the base address when deploying in IIS, we do not need to configure the base address in the configuration file. This is the base address of the service:
After the deployment is successful, we click on the .svc file to view the service:

Generate client proxy from endpoint address WCF service

Is it possible for a WCF Service with two endpoints to provide a way, for the client, to generate his proxies from a specific endpoint ? I'm currently using the "Add Service Reference" feature from VS 2013 and it will obtain all classes defined by two contracts.
My two contracts define differents request/response. IServiceTCP provide admin-like methods and in IServiceHttp user-like methods.
Since I got a client who will only communicate in HTTP and he's not in the same network (making the endpoint in tcp useless), I would like to provide him a way to generate his proxies getting only classes needed from the http contract.
It seems I can provide an address to the endpoint that will be appended to the base address of the service. Since I'm hosted behind an IIS server, if I give the address "testhttp" to my endpoint, it would be resolved as "http://localhost/MyService/Service.svc/testhttp". I didn't found a way for a client to consume that address.
<service name="Namespace.Service" behaviorConfiguration="ServiceBehaviorA">
<endpoint binding="wsHttpBinding" bindingConfiguration="ServiceBindingHttp" contract="Namespace.IServiceHttp" />
<endpoint binding="netTcpBinding" bindingConfiguration="ServiceBindingTCP" contract="Namespace.IServiceTCP" />
</service>
I would like to avoid creating two services to achieve this purpose.
Thanks,
Not sure if this can be achieved without creating two services. If you're trying to create two endpoints, this is what you should try:
Give the two endpoints different service name:
<service name="Namespace.ServiceA" behaviorConfiguration="ServiceBehaviorA">
<endpoint binding="wsHttpBinding" bindingConfiguration="ServiceBindingHttp" contract="Namespace.IServiceHttp" />
</service>
<service name="Namespace.ServiceB" behaviorConfiguration="ServiceBehaviorA">
<endpoint binding="netTcpBinding" bindingConfiguration="ServiceBindingTCP" contract="Namespace.IServiceTCP" />
</service>
<serviceHostingEnvironment >
<serviceActivations>
<add relativeAddress="ServiceA.svc" service="Namespace.ServiceA" />
<add relativeAddress="ServiceB.svc" service="Namespace.ServiceB" />
</serviceActivations>/serviceHostingEnvironment>
Now the two endpoints should be accessible via
http://localhost/MyService/ServiceA.svc
http://localhost/MyService/ServiceB.svc
HTH.

Hosting WCF on IIS - EndpointNotFoundException

After implemeting a WCF service, hosting it on the IIS Server, it returned with the below error.
EndpointNotFoundException was unhandled by user code There was no
endpoint listening at XXXXX that could accept the message. This is
often caused by an incorrect address or SOAP action. See
InnerException, if present, for more details.
That service is identically has the same implementation and configuration of 5 running services with no errors.
when I tried to figure out what is going on the IIS server, the below screenshot.
So it seems that this specific service has no detected Contract. although I'm using the same configuration as below.
<service name="XX.XX.Provisioning.EldaftarManagementService">
<endpoint address="" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" bindingNamespace="http://XX.XX.com/XX/" contract="XX.XX.Provisioning.Eldaftar.IEldaftarManagementService" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="ProvisioningBasicBinding" bindingNamespace="http://XX.XX.com/provisioning/" contract="XX.XX.Provisioning.Eldaftar.IEldaftarManagementService" />
</service>
<service name="XX.XX.Provisioning.Common.UserManagement.UserManagementService">
<endpoint address="" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" bindingNamespace="http://XX.XX.com/XX/" contract="XX.XX.Provisioning.Common.UserManagement.IUserManagementService" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="ProvisioningBasicBinding" bindingNamespace="http://XX.XX.com/provisioning/" contract="XX.XX.Provisioning.Common.UserManagement.IUserManagementService" />
</service>
Kindly noted that when accessing the service.svc url it replies normally and the wsdl is shown. So that means it's hosted fine on the IIS.
Do I miss something?
Update:
Client config.
<endpoint address="https://XXX/EldaftarManagementService.svc" behaviorConfiguration="ProvisioningClientBehaviour" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" contract="EldaftarManagementService.IEldaftarManagementService" />
<endpoint address="https://XXX/UserManagement.svc" behaviorConfiguration="ProvisioningClientBehaviour" binding="customBinding" bindingConfiguration="ProvisioningServiceBinding" contract="UserManagementService.IUserManagementService" />
i notice sometime after reconfigure my service reference, the client config getting wsdl with server name. then i get EndpointNotFoundException exception.
example :
service reference is : http://192.168.61.2:1111/Service1.svc
but in the config endpoint address it show : http://serverName:1111/Service1.svc
After i change the config endpoint address with the service reference address , then it resolved. Not sure why but now every time when i reconfigure the endpoint address, i will manually change the config endpoint address to make sure it get the same address.

Wcf decrease client connection timeout

I have a wcf service that works fine. The problem is the client. I have a little gui where the user is supposed to place the ip address of where the wcf service is located. Both the client and service are on the same network so if I am not able to connect it is because I provided an incorrect ip address or because the firewall is blocking. Anyways how can I shorten that time so that if the user types the incorrect ip he does not have to wait like 20 seconds? Here is how my app.config file looks for my client:
Here is how my client app.config file looks:
<client>
<endpoint address="net.tcp://127.0.0.1:41236/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1"
name="NetTcpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
Edit
I have updated my app.config file to:
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService1" sendTimeout="00:00:02" receiveTimeout="00:00:02">
<security mode="Transport" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://10.10.1.154:41236/"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1"
contract="ServiceReference1.IService1"
name="NetTcpBinding_IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
note I am placing an ip address that does not exist on purpose and for some reason the program still waits for like 10 seconds... I added sendTimeout="00:00:02" receiveTimeout="00:00:02" attributes and still did not work :(
Edit 2
Here is the error message that I get:
Could not connect to net.tcp://10.10.1.154:41236/. The connection
attempt lasted for a time span of 00:00:21.0342031. TCP error code
10060: A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection
failed because connected host has failed to respond 10.10.1.154:41236.
Note it attempted to connect for 21 seconds... I knew I was not going to be able to connect but it will be nice if I could reduce that time. I am planning to use this program on the same network...
On your NetTcpBinding_IService1 bindingConfiguration
add an attribute sendTimeout="00:00:02"
This will reduce it to 2 seconds.
Edit
Please use OpenTimeout="00:00:02" this should work.
replace timeout in your bindingConfiguration NetTcpBinding_IService1
An answer for this has been given here wcf-channelfactory-and-opentimeout. It has something to do with sockets timeout. It seems that a workaround is needed.

List wcf service addresses when no address or baseaddress is specified in the web config

How do I get all the wcf 4.0 service addresses from each project in the Visual Studio solution when the services section endpoints in the web configs don’t specify an address or baseaddress? I intend to write the list of service addresses out to an aspx page. Any help would be appreciated.
Here's an example of one of the service sections in the web config.
<services>
<service name="ABC.Enterprise.Flight.FlightService">
<endpoint address="" binding="basicHttpBinding" name="ICRMManagement" contract="ABC.Enterprise.Flight.IFlightService"/>
<endpoint address="MexBasic" binding="mexHttpBinding" name="MexBasic" contract="IMetadataExchange" />
</service>
You could use WCF Discovery to find endpoints at runtime...
http://msdn.microsoft.com/en-us/library/dd456791.aspx

Categories