WCF Test Service cannot add service - visual-studio

I'm using Visual Studio for a school project and I'm to create a simple WCF Service Application web service that I need to test using WCF Test Client.
I developed the service, but then when I run the debugger, it opens a web browser, I copy the link to the IService1.svc file, and try to add that to the test client, and it fails complaining it cannot get meta data.
I tried this on a fresh solution with a new project, and same thing.
My Web.config file:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.8.1" />
<httpRuntime targetFramework="4.8.1"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</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>
Am I missing any steps in testing the web services?

Depending on your wcf configuration file, you can see the parts without endpoints and service contracts. You may have missed the <service.model> section:
<services>
<service name="Namespace.Service1">
<endpoint address="" binding="basicHttpBinding" contract="Namespace.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>

Related

WCF service And Linq

I am using LINQ in a WCF service. I am trying to list all my movies in a grid but my query wont work.
any of you know why?
this is the query:
public List<MovieInfo> GetAllMovies()
{
var queryResult = (from x in db.MovieInfos
select x);
return queryResult.ToList();
}
This is the webconfig:
<configuration>
<connectionStrings>
<add
name="dmaa0913Sem3_1ConnectionString"
connectionString="Data Source=dbname;Initial Catalog=dataname;Persist Security Info=True;User ID=username;Password=password"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</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>
here is the error i get:
Failed to invoke the service. Possible causes: The service is offline
or inaccessible; the client-side configuration does not match the
proxy; the existing proxy is invalid. Refer to the stack trace for
more detail. You can try to recover by starting a new proxy, restoring
to default configuration, or refreshing the service.
The service is online, because i use WCF test client.
I have solved the problem. The query that i use for extracting data from the database i somthing called lazyloading. And WCF have trouble working with this kind of query if the data that need's to be extracted is to complex. It is somthing about how WCF service serialize the service. So what i did to make it work was to go in the Linq datacontex and set the. Serialization Mode to Unidirectional. This worked for me.

Deploying a WCF service to IIS 6

I created a wcf service using VS2010 and it works correctly, when I run it from VS2010, but when I deploy it on IIS 6(according this post), It does not work.
I did this steps:
I created a folder in my server(C:\WCFServices\HRService) and copied HRService.svc and web.config to it and grant full access to this folder for ASPNET user.
I created a Bin folder in the above folder and copied my service dll in it.
I Created new virtual directory in my default web site(HR):
My .svc files , web.Configs are as below:
My .svc file
<%# ServiceHost Language="C#" Debug="true" Service="HumanResourceService.HRService" %>
And my web.Config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" />
</basicHttpBinding>
</bindings>
<services>
<service name="HumanResourceService.HRService">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="" contract="HumanResourceService.IHRService" >
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
But when I want to access my WCF service via IE I get this error:
Could anyone tell me, what is the problem?
Make sure the the name for the service in the configuration file matches the .svc file. In your posted code it doesn't. Your .svc file has "HumanResourceService.HRService", so the name attribute for the <service> element should match:
<service name="HumanResourceService.HRService">
Also, is this a RESTful service or SOAP? I ask because you are using the webHttpBinding for your service, which is for REST. If it's not, I suggest basicHttpBinding or wsHttpBinding.
If it is REST, then add this to the behavior section of your config file:
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
I found the problem.
In IIS and in Web Service Extensions section, the ASP.NET V4.0.30319 status was Prohibited and I changed it to Allowed and the problem solved.

Slow invoking of WCF service

So my issue is kinda simple but can't figure out how to deal with it.
I am using a wcf service which is accessing database through ADO.NET Entity Framework and after that I use this service to get the data in windows phone 7 application. The problem is when I call a simple select * from table the data gets populated in my WP7 for like 6-7 seconds which seems to me kinda long. I can post the web.config if needed but I havent changed much from what was generated from VS.
Anyone had the same issue or know how to deal with that?
I put my web.config, I thik problem should be there maybe.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings />
<client />
<services>
<service name="WcfServiceForWinMobile.Service1" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="WcfServiceForWinMobile.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://89.215.65.163/WcfServiceForWinMobile/Win7MobileService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<connectionStrings><add name="CompanyEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=xetyccwqk6.database.windows.net;initial catalog=Company;persist security info=True;user id=company;password=Plovdiv12345;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings></configuration>

WCF Service, the type provided as the service attribute values...could not be found

I have this issue a long time ago and just cannot recall how to resolve it or perphaps its something new. I created a WCF service which I will later use in web application that calls the WCF service amongst others from a remote location. Right now I am trying to host in IIS and even tried the WCFTestClient. The error I get when I try to browse to the service; is the following:
The type MyService.Service1 provided as the Service attribute
value in the ServiceHost directive, or provided in the
configuration element system.serviceModel/serviceHostingEnvironment/
serviceActivations could not be found.
I figured its probably my web.config file but I cannot see whats wrong:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" crossDomainScriptAccessEnabled="false" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="webHttpBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="webHttpBehavior" name="WcfInstanceRules2.Service1">
<endpoint address=""
binding="webHttpBinding"
contract="WcfRules2.IServiceS" behaviorConfiguration="web"/>
<endpoint address="mex"
binding="webHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
I would like this to be eventually a rest service delivering data in json format.
Check your .svc file and see what service it's referencing - probably MyService.Service1, which doesn't exist in your config. It looks like it should be referencing WcfInstanceRules2.Service1.

wcf service no config file when adding service reference

I have a wcf service that I tried to add using both svcutil and by adding service reference to the client test project. In both cases a new config file was not created and subsequently the client test will not run due to it not seeing the endpoints. Why is this the case and here is my web.config file for the WCF service.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="webHttpBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="webHttpBehavior" name="WcfInstanceRules2.Service1">
<endpoint address=""
binding="webHttpBinding" bindingConfiguration="webHttpBinding"
contract="WcfInstanceRules2.IService1"
behaviorConfiguration="web"/>
</service>
</services>
If you're using the webHttpBinding then you're writing a RESTful service, right? REST services aren't "consumed" via Visual studio or via SvcUtil.exe like other SOAP based services (for example, that would use a SOAP based binding like basicHttpBinding, or wsHttpBinding etc). You would "consume" the service by calling it from something like jQuery:
$.getJSON("Service1.svc/uriTemplateNameHere", { param: myParameter },
function (result) {
// do something
});
Can you post your WCF code?

Resources