I have a sweet WinForm application (on my computer) and a SQL Server database (on server X). I'm using SqlConnection and everything works fine.
But not I want to change it and use WCF or other technologies to connect and switch information between my app and database.
I also have one more server to use as application server (Server Y).
I've started using WCF: created project, created installer.
Uploaded it on my Y server and installed it. Service started, also I've added Service Reference to my WinForm app, but the ServiceClient is not working properly.
When I call ServiceClient's method it throws exception:
An exception of type 'System.ServiceModel.EndpointNotFoundException' occurred in mscorlib.dll but was not handled in user code
Additional information: There was no endpoint listening at http://localhost:41272/service that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
As I guess my endpoint is blowing things up.
So I want you guys help me how to configure SQL endpoint.
Here is my WCF's web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime />
<pages controlRenderingCompatibilityVersion="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="SampleSvcBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="SampleSvcBehavior"
name="FMG_WCF.FmgService">
<endpoint name="SampleSvcBasicHttpEndPoint"
address=""
binding="basicHttpBinding" bindingConfiguration=""
contract="FMG_WCF.IFmgService" />
<endpoint name="SampleSvcMexHttpEndPoint"
address="mex"
binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:41272/service" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
This error is not related with SQL endpoint. In facts you do not need endpoints for connecting WCF to database. Here is your answer in another post.
EndpointNotFoundException - 404 - Hosting WCF Service over HTTPS in IIS through Visual Studio
You have two options, if the service has been modified from when you created it you can simply right click on the service reference and configure the service reference. In the popup you can change the Url to point to serverX and you service reference and config file will be automatically updated.
If no changes were made to the service, for example your binding type or security then simply updating the Url in the config file should be enough.
Related
I have a WCF Service Application project in Visual Studio that contains the following files
ZooWebService.svc
WebConfig
I attempted to host the Web Service in IIS but when i browse to my web service from IIS the Web Service does not load at all. It just says "loading" in the browser.
Here is my WebConfig file:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="Default"
name="WCFWebService.ZooWCFService">
<endpoint address="" binding="basicHttpBinding"
contract="WCFWebService.IZooWCFService" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I did the following so what have i done wrong?
Open IIS
Right clicked on Default Website
Selected "Add Application"
Populated "Alias" field
Populated "Physical Path" to directory of where the solution contents are
Clicked OK
Rebuilt the solution in Visual Studio
We don’t need to specify the base address in the configuration file which needs to be set up in the web site binding module.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d42fc165-052d-476a-9580-1240b3d0293d/specify-endpoint-in-wcf-webconfig?forum=wcf
then we should enable the WCF feature in the IIS.
At last we could see the web service description in http://ip:port/xxxx.svc.
Feel free to let me know if there is anything I can help with.
For enabling the WCF in IIS, you may have to enable the HTTP activation feature for the .net framework first.
Some of links to do this
https://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20full%20documentation-v1/GUID-326D6F7B-08EC-43EB-A5A7-9C51DD9E555C
https://pubs.vmware.com/mirage-56/index.jsp?topic=%2Fcom.vmware.mirage.api.pg.doc%2FGUID-552D845B-E530-4898-A06B-4F73E668BEFF.html
Once this is done you may try to deploy WCF directly from the visual studio to your local IIS>
Right click on the WCFproject -> go to properties -> in properties window -> select web tab -> in servers section select Local IIS and click on Create Virtual Directory.
Now run the WCF from Visual studio, this will host the WCF in local IIS.
I have a very weird problem with a 3 tiers client/server application with WCF.
First, I have a service windows which host WCF services in basicHttpBinding. This is the server app.config :
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Business.BSServiceManagement" behaviorConfiguration="myServiceBehave">
<host>
<baseAddresses>
<add baseAddress="http://localhost:35001"/>
</baseAddresses>
</host>
<endpoint address="/Clients" binding="basicHttpBinding" name="Clients" contract="Contracts.BusinessFacade.IBFClientManagement"/>
<endpoint address="/Users" binding="basicHttpBinding" name="Users" contract="Contracts.BusinessFacade.IBFUserManagement"/>
<endpoint address="/Licences" binding="basicHttpBinding" name="Licences" contract="Contracts.BusinessFacade.IBFLicenceManagement"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehave">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
This service is deployed on a server in DMZ and I have access from my computer (in firefox, if I put service address with port number)
Secondly, I have a client application made with winforms which consume the service with ChannelFactory.
This is the client app.config :
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://192.168.128.1:35001/Clients" binding="basicHttpBinding" name="Clients" contract="Contracts.BusinessFacade.IBFClientManagement"/>
<endpoint address="http://192.168.128.1:35001/Users" binding="basicHttpBinding" name="Users" contract="Contracts.BusinessFacade.IBFUserManagement"/>
<endpoint address="http://192.168.128.1:35001/Licences" binding="basicHttpBinding" name="Licences" contract="Contracts.BusinessFacade.IBFLicenceManagement"/>
</client>
</system.serviceModel>
</configuration>
When I debug client application, all works perfectly. So I've made a installer project to deploy application on several computers but when I execute exe of application (installed or directly in bin/release), I have an error message like this :
There was no endpoint listening at http://192.168.128.1:35001/Users...
The inner exception says:
Unable to connect to the remote server
I tried adding mex endpoint, change port number, check server and client computer firewall, I don't understand where is the problem.
Thanks for your help.
EDIT 1 :
After several tests I have the same problem in release exe but not in debug exe.
If I execute the debug exe all works fine but the release exe return the error message.
The problem is with your Service.
Make sure that the Service is Started and running.
Once you start the Service, browse URL(eg: localhost:8080/example), just to make sure Service is running fine.
When you add Service Reference to your client Application, it automatically generates endpoints in app.config file.
When you added Installer to client project, make sure that it is builds Successfully.
When you install it, it should work for you.
I have created a WCF service and hosted it in a windows service. Testing this service with visual studio works fine and I can consume it. Now I have installed the service on a PC (called PC1) and using another PC (called PC2) I wish to be able to discover it and consume it. I imagine that I will have to modify the app.config file to achieve this.
Here is my current app.config, what do I need to modify to get this to work from other networked computers? I'm guessing the base address is a start?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfAVOLibrary.AVOs">
<endpoint address="" binding="wsDualHttpBinding" contract="WcfAVOLibrary.IAVOs">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfAVOLibrary/AVOs/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values 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>
</system.serviceModel>
</configuration>
oh and i'm running .Net 4.5
(if the web service is not implemented, I recommend this link
http://www.codeproject.com/Articles/28693/Deploying-ASP-NET-Websites-on-IIS-7-0)
You should try to modify the web.config in this place:
<baseAddresses>
<add baseAddress="http://192.168.1.2/Design_Time_Addresses/WcfAVOLibrary/AVOs/" />
</baseAddresses>
where 192.168.1.2 is your current ip, or localhost works too, it would see like this:
<baseAddresses>
<add baseAddress="http://localhost/Design_Time_Addresses/WcfAVOLibrary/AVOs/" />
</baseAddresses>
At first place, change localhost by pc1 on base address, like
http://pc1:8733/Design_Time_Addresses/WcfAVOLibrary/AVOs/
After it, try to open the base address url from browser on pc2 (yes, never mind that it is win. service - this is your service url and should be accessible). It should be ok, you need not to continue before you get it work.
When it done - review client's config to match service address.
Was facing the same issue. Added inbound rule to open the port 8733 in Windows Firewall. It worked!
I am having a WCF ServiceLibrary which runs successfully on WCF Test Client.
Now I am trying to build a Website to Host this web service. I am using nettcp binding. My web.config file looks like this
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="tcp_Unsecured" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="tcpServiceBehavior" name="MarketFeedServiceLibrary.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="tcp_Unsecured"
name="data" contract="MarketFeedServiceLibrary.IService1" />
<endpoint address="mextcp" binding="mexTcpBinding" name="metadata"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="tcpServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I am try to view in browser directly from Solution Explorer
But I get error as shown below
Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
I have tried all the solutions available on SO, youtube etc but no luck,
I tried:
Under IIS I have enabled http,net.tcp protocols
I have also gone through: How to: Install and Configure WCF Activation Components
N.B. I am a WPF App Developer, hence WCF and ASP.NET Website are new to me.
Thank You.
Edit: Testing Under WCF Client gives following error
Cannot obtain Metadata from net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. WS-Metadata Exchange Error URI: net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc'. Could not connect to net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc. The connection attempt lasted for a time span of 00:00:01.9968000. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8080. No connection could be made because the target machine actively refused it 127.0.0.1:8080
One of my methods returns byte[], of a file. All other methods return either string objects or custom objects
I can view the WSDL via a browser and as i have used WCfExtras, I can even view the documentation.
In my test app, C# web application, I add the reference to my svc, hosted on a test server. I get an error as such:
The document was understood, but it could not be processed.
- The WSDL document contains links that could not be resolved.
- There was an error downloading ...
- Unable to connect to remote server
- No connection could be made because the target machine actively refused it
Content Type application/soap+xml; charset=utf-8 was not supported by service . The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
This is my app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="TestApp.Properties.Settings.TestDBConnectionString"
connectionString="Data Source=192.168.2.130;Initial Catalog=TestDB;Persist Security Info=True;User ID=sa;Password=xerox"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="TestApp.Service1Behavior"
name="TestApp.SearchService">
<endpoint address="" behaviorConfiguration="Sample.WsdlSampleEndpointBehavior"
binding="basicHttpBinding" bindingConfiguration="WsHttpMtomBinding" contract="TestApp.ISearchService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/TestApp/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Sample.WsdlSampleEndpointBehavior">
<wsdlExtensions location="http://localhost:8731/TestApp/Service1/"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="TestApp.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="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<!-- Declare that we have an extension called WSDL Extras-->
<add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<bindings>
<basicHttpBinding>
<binding name="WsHttpMtomBinding" messageEncoding="Mtom" transferMode="StreamedResponse" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
Any ideas on how I would resolve this? Should I have 2 different bindings, one for methods returning non bytes[] and Mtom for method returning byte[]? If so how does one apply bindings per method exposed?
Tried running it with WcfTestClient.exe and this is the error
rror: Cannot import wsdl:portTypeDetail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporterError: Schema with target namespace 'http://tempuri.org/' could not be found.XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='ISearchService']Error: Cannot import wsdl:bindingDetail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.XPath to wsdl:portType: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='ISearchService']XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='BasicHttpBinding_ISearchService']Error: Cannot import wsdl:portDetail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.XPath to wsdl:binding: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='BasicHttpBinding_ISearchService']XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:service[#name='SearchService']/wsdl:port[#name='BasicHttpBinding_ISearchService']Warning: No code was generated.If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or servicesor because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.
I have the same problem. I was hosting the wcf on remote win2008 server on IIS. The solution that has worked for me was setting the host name when adding web site and don't leave it blank after setting all other data for hosting!
On the client app, do you have a reference to the WCFExtras assembly? The error appears to be saying that the binding is not recognized, which is, I assume, because of the extensions introduced by WCFExtras. Try adding the same extensions section to your client's config file as is in the server's config file.
Your binding is basicHttpBinding, but your binding configuration is wsHttpMTOMBinding.
This looks like a mismatch, however it could be just the names that you have given things.
Try opening the config file in the WCF config tool, this should tell you (refuse to open the file), if there are inconsistencies in your config file.
Hope this helps
Shiraz
This can't be a true answer, but after I removed WCfExtras references from my app.config file and deployed, things seem to work.
This is what I was trying to achieve, but have abandoned for time being
WCF Extras
If anyone has an idea of how and what I configured wrong, please advise on this column.
Many Thanks
The answer for me to be able to use the WCF Test Client is to set the set singleFile="true" in the web config like this.
<behavior name="Sample.WsdlSampleEndpointBehavior">
<wsdlExtensions location="http://localhost:8731/TestApp/Service1/" singleFile="true" />
</behavior>