at the beginning sorry for my English.
I know that there are already answers for this question but none of them worked for me.
I am trying to connect to my database.
I am working on:
Microsoft Visual Studio Community 2015 version 14.0.25431.01 Update 3.
Microsoft .NET Framework Version 4.6.01586
I have already checked Tools->Options->Project and Solutions->Web Projects->Use the 64 bit version of IIS Express for web sites and projects.
My code from View Markup (Service1.svc):
<%# ServiceHost Language="C#" Debug="true" Service="WCFconnection.Service1" CodeBehind="Service1.svc.cs" %>
here is my Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXX" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<services>
<service name="WCFconnection.Service1"
behaviorConfiguration="metadataBehavior">
<endpoint address="" binding="basicHttpBinding" contract="WCFconnection.IService1" />
<endpoint address="basic" binding="basicHttpBinding" contract="WCFconnection.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="localhost:23233/Service1.svc"
binding="basicHttpBinding"
contract="WCFconnection.IService1"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<directoryBrowse enabled="true" />
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<connectionStrings>
<add name="ZPIEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=XXXXXX-XXXXXX;initial catalog=XXXXXX;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="ConStr" connectionString="Data Source=XXXXXXX-XXXXXXXX\XXXXXXX;Initial Catalog=XXXXXXX;Integrated Security=True"/>
</connectionStrings>
<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>
When I go to website and put localhost:23233 into address I can see all the files, also my Service1.svc. But if I try to make WcfTestClient I got error:
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
Error: Cannot obtain Metadata from http://localhost:23233/ 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...
Please help me.
Based on the error that WcfTestClient is giving you, you are not providing the full endpoint url.
You are adding http://localhost:23233/
You should be adding http://localhost:23233/Service1.svc
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've set up a RESTful WCF web service on our server (IIS 8.5 running on Windows Server 2012 R2). I can connect remotely and run exposed methods no problem.
I get a problem when the method contains a connection to a database. Despite having windows authentication set up in IIS, the username passed through to the database is defaulting to the machine default, which is wrong.
I'm currently using this web.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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<identity impersonate="true"/>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<system.serviceModel>
<services>
<service name="AriaRestFul2.Service1" behaviorConfiguration="AriaRestFul2.Service1Behavior">
<endpoint address="../Service1.svc" binding="webHttpBinding" contract="AriaRestFul2.IService1" behaviorConfiguration="webBehaviour" bindingConfiguration="restbinding">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="webHttpBinding" contract="IMetadataExchange" bindingConfiguration="restbinding"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AriaRestFul2.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="restbinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<httpErrors errorMode="Detailed" />
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false"/>
<directoryBrowse enabled="true" />
</system.webServer>
<connectionStrings>
<add name="AriaEntities" connectionString="metadata=res://*/Aria.csdl|res://*/Aria.ssdl|res://*/Aria.msl;provider=System.Data.SqlClient;provider connection string="data source=<instance>;initial catalog=Aria;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<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>
The database I'm connecting to is through EF6. I'm using chrome as the client to pass in the URL to the service. I'm worried that this setup might require the credentials to be assigned in code in a client. If this is the case, is there anyway I can configure the service to just pass through the current user from the browser?
I am trying to call a web service from a another WCF using custom C# code. However when I run my code, I get the following error:
However it executed successfully when i ran it from Asp.net page.
Here is my service webconfig file
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2"/>
<httpRuntime targetFramework="4.5.2"/>
<httpModules>
<add name="ApplicationInsights" type="Microsoft.ApplicationInsights.Telemetry.Web.ApplicationInsightsModule"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<connectionStrings>
<add name="TesString" connectionString="Data Source=(localdb)\Kentico;Initial Catalog=MYDB;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BillUploadSoap1"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://testapp2.com/ssb/financial/billupload.asmx" binding="basicHttpBinding" bindingConfiguration="BillUploadSoap1"
contract="SCTHSadad.BillUploadSoap" name="BillUploadSoap1"/>
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
<!--
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"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
I think you are trying to consume an asmx web service as a WCF service in your client.
When you add the service reference, try as below -
And delete all the config and binding info in your client app.
I have a Silverlight 5 Web Application that I host in IIS 8. I can run my application fine in VS 2013 but on Deploying to a Windows 2012 server running IIS 8, my app fails to run. Fiddler gives me the following:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
My Web.config file is shown below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="system.serviceModel">
<section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key="ApplicationName" value="......" />
</appSettings>
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</httpModules>
<httpRuntime targetFramework="4.5" maxRequestLength="10000000" executionTimeout="120" />
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<roleManager enabled="true" />
<authentication mode="Forms">
<forms name=".ABCD_ASPXAUTH" timeout="20" />
</authentication>
<profile>
<properties>
<add name="FriendlyName" />
</properties>
</profile>
<pages controlRenderingCompatibilityVersion="4.0" />
<customErrors mode="RemoteOnly" defaultRedirect="DefaultRedirectErrorPage.aspx">
<error statusCode="403" redirect="AccessDenied.htm" />
<error statusCode="404" redirect="Http404ErrorPage.aspx" />
</customErrors>
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true" requireSSL="false" />
<roleService enabled="true" />
</webServices>
</scripting>
</system.web.extensions>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3765AD364E35" />
</modules>
</system.webServer>
<system.serviceModel>
<client />
<behaviors>
<serviceBehaviors>
<behavior name="AppServicesBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="ReportServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="userHttp">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="System.Web.ApplicationServices.AuthenticationService" behaviorConfiguration="AppServicesBehavior">
<endpoint contract="System.Web.ApplicationServices.AuthenticationService" binding="basicHttpBinding" bindingConfiguration="userHttp" bindingNamespace="http://asp.net/ApplicationServices/v200" />
</service>
<service name="System.Web.ApplicationServices.RoleService" behaviorConfiguration="AppServicesBehavior">
<endpoint contract="System.Web.ApplicationServices.RoleService" binding="basicHttpBinding" bindingConfiguration="userHttp" bindingNamespace="http://asp.net/ApplicationServices/v200" />
</service>
<service name="Telerik.Reporting.Service.ReportService" behaviorConfiguration="ReportServiceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="Telerik.Reporting.Service.IReportService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="resources" binding="webHttpBinding" behaviorConfiguration="WebBehavior" contract="Telerik.Reporting.Service.IResourceService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<connectionStrings>
''''''''''''''''
</connectionStrings>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Critical, Error, Warning" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\Projects\Log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
Can someone tell me why a previously configured Win 2012 server does not now load the deployed application when I can still run from VS 2013?
Or is there a way to get Fiddler to give a more detailed error?
I set Tracing on, but the log does not give any better clues.
Thanks.
Chances are you have RIA Services installed on your development machine but it is not installed on the server.
You have two choices:
Remember to install RIA Services on each server you deploy to
Add the RIAServices.Server NuGet package to your *.Web project. This will add private local copies of the RIAServices dll to your solution.
I have just switched from WCF Service to Windows Azure Cloud Service.
I have copied over my codes from my WCF service into the Cloud service.
When i run the website i get
500 - Internal Server Error.
There is a problem with the resource you are looking for, and it cannot be displayed.
Here is my code for my Web.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="PCSDB" connectionString="Data Source=vlnucbukr8.database.windows.net;Initial Catalog=PCSDB;User ID=ProjectPublicLogin;Password=****" providerName="System.Data.SqlClient" />
</connectionStrings>
<configSections>
</configSections>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<services>
<service name ="WCFServiceWebRole1.AllocationService">
<endpoint address="" behaviorConfiguration="AllocationBehavior" binding="webHttpBinding" bindingConfiguration="" contract="WCFServiceWebRole1.IAllocationService">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost/allocationservice"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="AllocationBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
<httpErrors>
<remove statusCode="500" subStatusCode="100" />
<error statusCode="500" subStatusCode="100" prefixLanguageFilePath="" path="/errors.asp" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
Found the solution..
<configSections> </configSections>
have to be the first child of the
<configuration>
tag
Rather than Copying the whole code from service to cloud proejct, Add a Cloud project in Solution and then right click roles and add existing role from solution.