My problem is with binding. It works when i run my client in debug mode but it doesn't work in release mode.
Server and client run on the same computer.
Unhandled Exception: System.ServiceModel.EndpointNotFoundException:
There was no endpoint listening at http://localhost:8733/Design_Time_Addresses/ServiceLibrary/Service1/ that
could accept the message. This is often caused by an incorrect address or SOAP
action. See InnerException, if present, for more details.
Server App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<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="ServiceLibrary.Service" behaviorConfiguration="metadataAndDebug">
<endpoint address="" binding="basicHttpBinding" contract="ServiceLibrary.IService">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/ServiceLibrary/Service1/" />
</baseAddresses>
</host>
<!-- 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>
<!--
Step 2. Inside a <serviceBehaviors> section, add
a name attribute in the <behaviors> element that
matches the behaviorConfiguration attribute in the
<service> element above.
-->
<behavior name="metadataAndDebug">
<serviceMetadata httpGetEnabled="true" httpGetUrl="" httpsGetEnabled="True" />
<!--
Step 3. Add a <serviceDebug> element and
modify the various attributes that suit your
scenario.
-->
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Client App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/ServiceLibrary/Service1/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="ServiceReference.IService" name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
</configuration>
Any solution?
Related
I have a publish-subscribe notification running with wcf duplex wsdualhttpbinding. But when I started to subscribe in client side, I got the message:
"Could not find endpoint element that references contract in the ServiceModel client configuration section.This might be because no configuration file was found for your application or because no endpoint element matching this contract could be found in the client element"
App.config client
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IRecipeTemplateService" />
<binding name="Basic1" />
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://172.18.26.14/CentralService/Services/NotificationService.svc"
binding="wsDualHttpBinding" bindingConfiguration="Basic1"
contract="CentralNotificationService.INotificationService"
name="Basic1">
<identity>
<servicePrincipalName value="host/myclienthost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Web.config
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<connectionStrings>
<add name="RecipeDB" providerName="MySql.Data.MySqlClient"
connectionString="Server=localhost; Port=3306; Database=recipe_db; Uid=root; Pwd=root" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework"/>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.28.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<system.serviceModel>
<services>
<service behaviorConfiguration="mexBehavior" name="RecipeServer.Central.Service.Services.NotificationService">
<endpoint address="" binding="wsDualHttpBinding"
name="Basic" contract="RecipeServer.Central.Service.Interfaces.INotificationService" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="mexdata" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="wsDualHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Code in client side
InstanceContext site = new InstanceContext(new ServiceCallBack());
try
{
client = new NotificationServiceClient(site);
}
catch (Exception e) {
RecipeLogger.GetInstance.ErrorLog(e.Message);
RecipeLogger.GetInstance.ErrorLog(e.StackTrace);
}
WSDualHttpBinding binding = (WSDualHttpBinding)client.Endpoint.Binding;
RecipeLogger.GetInstance.DebugLog("2");
binding.ClientBaseAddress = new Uri("http://localhost:8000/myClient/");
string clientcallbackaddress = binding.ClientBaseAddress.AbsoluteUri;
RecipeLogger.GetInstance.DebugLog(String.Format("Client baseadd {0}", clientcallbackaddress));
clientcallbackaddress += Guid.NewGuid().ToString();
binding.ClientBaseAddress = new Uri(clientcallbackaddress);
RecipeLogger.GetInstance.DebugLog("Subscribe to central");
client.Subscribe();
client.Close();
After having fixed this issue for nearly a week, I realized that I have multiples project in a solution, and the initial project was service project, and it had a web.config, so when run the project, the VS read the web.config and ignored all app.config at others project.
So the solution here is I just moved all settings code in app.config into web.config
I have a wcf self hosted service that is meant to be consumed by both computers and android phones. i successfully made the service consumable in both targets but when i built an exe file (which is responsible for self hosting the service) the service worked great in the pc but it did not work on the mobile app.
here is my service's app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<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>
<bindings>
<basicHttpBinding>
<binding name="httpBinding" maxBufferSize="128000000" maxReceivedMessageSize="128000000" />
</basicHttpBinding>
<webHttpBinding>
<binding name="webBinding" closeTimeout="00:02:00" sendTimeout="00:02:00"
maxBufferSize="6553600" maxReceivedMessageSize="6553600" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<diagnostics performanceCounters="Default" />
<services>
<service name="DeltaService.Data">
<endpoint address="data" binding="basicHttpBinding" bindingConfiguration="httpBinding"
name="data" contract="DeltaService.IData">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="json" behaviorConfiguration="Rest" binding="webHttpBinding"
bindingConfiguration="webBinding" name="restdata" contract="DeltaService.IData">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/delta_api/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Rest">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" />
</behavior>
<behavior name="Web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<useRequestHeadersForMetadataAddress />
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
and here is the code that launches the service:
serviceHost = new ServiceHost(typeof(Data));
NetHttpBinding netHttpBinding = new NetHttpBinding();
netHttpBinding.MaxReceivedMessageSize = 128 * 1000000; //128Mb
serviceHost.AddServiceEndpoint(typeof(IData), netHttpBinding, url);
erviceHost.Open();
It seems that you host the service by using other hosting programs. One thing we must take into consideration is that we needn’t configure the service endpoint and binding information when hosting the service in a hosting program(such as WinForms application).
There is a distinction when hosting in those two ways. When we hosting the service by running on the Visual studio, the system will automatically search for the service configuration, thus the configuration in the Appconfig file will take effect, proper binding generates different kinds of service (restful and soap web service). But the service by using NetHttpBinding will be different from the aforementioned service when hosting the service in other programs.
In a word, I suggest you use below code in the self-hosting program.
ServiceHost sh = new ServiceHost(typeof(Data));
sh.Open();
It will automatically search for the service configuration in Appconfig file so that the service will be published in proper ways.
Feel free to let me know if the problem still exists.
You have configured your address to be localhost. That address can only be reached from your computer, not from the outside.
When you host your service, pick an address that can be reached from the outside. As I don't know where your device is, I don't know how much "outside" you need. Local network? WAN? Make sure you read a tutorial on that and pick the address or DNS entry you need.
I've developed a WCF SOAP Web Service and for testing purposes i use SOAP UI but i have the following problem:
1) I test the Web service using the ip adress like this:
http://XXX.XXX.XXX.XXX:81/SIDIGE.Web.Service.CanDoc.svc?wsdl
and everything works FINE, I can use the web service without issues
2) Now if I test the Web service like this (using the hostname):
http://hp_webserver:81/SIDIGE.Web.Service.CanDoc.svc?wsdl
I get a 404 error when i POST info to the server (if I use the browser and type the address it works, no 404 error)
I've read all questions about this and nothing seems to work....any ideas?
My web.config is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="servidorRemoto" connectionString="Data Source=XXX\XXX; Initial Catalog=XXX" providerName="System.Data.SqlClient" />
</connectionStrings>
<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="SIDIGE.Web.Service.CanDoc" behaviorConfiguration="ServiceBehavior">
<endpoint address="CanDoc" binding="basicHttpBinding" contract="SIDIGE.Web.IService.ICanDoc" bindingNamespace="http://sidige.com/candoc" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://XXX.XXX.XXX.XXX:81" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<!-- Use your own port numbers -->
<add scheme="http" port="81" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>
The problem wasn't on my part or the configuration. It was the testing client (SOAP UI). It seems it has some issues with proxy networks.
My problem is that when I run my solution, I had no problems
Here is what service output looks like
And when I make the my link to like this
And it is correct
But when I deploy the solution, install it using setup from the installer i created
I can still access, but output goes like this
And I try to navigate it, it looks like this and it is not right because it has no output
How can I fix it? I thought it is already ok because when I run it in visual studio it gives me expected output but when i deploy it is not.
Service App.Config
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WcfServiceLibrary.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<compilation debug="true"/>
</system.web>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior0">
<webHttp defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="WcfServiceLibrary.Service">
<endpoint address="" behaviorConfiguration="NewBehavior0" binding="webHttpBinding"
bindingConfiguration="" name="Basic" contract="WcfServiceLibrary.IService" />
<host>
<baseAddresses>
<add baseAddress="http://PHWS13:8080/service" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
In the <behaviors> section you need to add
<serviceBehaviors>
<behavior name="NewSVCBehavior0"> >
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
And instead of
<service name="WcfServiceLibrary.Service">
write
<service name="WcfServiceLibrary.Service" behaviorConfiguration="NewSVCBehavior0">
and try after this change in config.
Thanks to stackoverflow (mostly), I have created a WCF service that is able to pull data from our ms sql database and relay it back in a json format. The service works as expected locally and on its home server within our network. However, I can't seem to access the service when outside the network.
Are there additional parameters needed in the code to accommodate being published over the web or is it possibly just a host setup and has nothing to do with WCF or the service?
The server is 2008 R2 & IIS 7.5 which is currently hosting a dozen or so of our websites. We have setup a port for the service as well.
This is the web.config file I am using:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
<services>
<service behaviorConfiguration="SrvcBehavior" name="Service.svc">
<endpoint address="JSON" behaviorConfiguration="JSONEndpointBehavior" binding="webHttpBinding" bindingConfiguration="" name="RESTEP" contract="Service.Isvc" />
<endpoint address="SOAP" binding="basicHttpBinding" name="Basic" contract="Service.Isvc" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="JSONEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="SrvcBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<connectionStrings>
<add name="conn" connectionString="server=SERVER-DATABASE\SQL2005;database=myDatabase;uid=USERID;password=USERPASSWORD;" />
</connectionStrings>
</configuration>