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.
Related
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>
We have a simple service configured as such:
<configuration>
<connectionStrings>
<add name="CONN" connectionString="Server=MYSERVER,1433;Database=mydb;User Id=user;Password=pass;"/>
</connectionStrings>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<services>
<service name="MyNamespace.MyService">
<host>
<baseAddresses>
<add baseAddress="https://mywebsite.com/TestService/"/>
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="MyNameSpace.IMyService" bindingConfiguration="defaultBinding" bindingNamespace="MyNameSpace"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="defaultBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferPoolSize="2147483647"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="false" 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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
The service was timing out before I added the additional arguments to binding name="defaultBinding" (closeTimeout, openTimeout, receiveTimeout, sendTimeout, maxbuffersize, maxreceivedmessagesize).
Our server has only TLS1.2 enabled.
The service is hosted in IIS and certificates seem to be okay - browsing the WSDL in the web looks okay.
Using SOAPUI on the same machine machine as the service is hosted times out (I assume this would be really quick?)
Is there a web config setting I am not aware of or does this come down to the server machine or possibly IIS?
Requests can take minutes to complete - even simple ones like a GetVersion() call that just returns a string. We even rebooted the machines, IIS, etc. and tried new requests - same issue.
Turns out my GetVersion() call actually had a LogActivity() call that would log to the database. The connection string in web.config was incorrect causing the database connection to spin until the database connection times out. The database connection timeout is set higher than the timeout for the service/client so the client would timeout before the database timeout occurred. The database connection timeout happens silently as there is no need to log a failed logging attempt for us.
Fixing the connection string has the service responding quickly.
Moral of the story: Double check your functions - even if they seem simple they might be doing some other stuff under the hood :)
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.
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?
I created a WCF service that returns a line of text and using a client application tested it and was able to retrieve the line of text. I thought that if I put the entire url in a browser that includes the method that returns the line of text it would work but instead I get a 400 not found error.
For example the main url is :
http://localhost/DataAdmin/GService.svc?wsdl
So when I try to past the following in a browser it does not work:
http://localhost/DataAdmin/GService.svc/RetrieveData?inputText=test
Oh, the reason for this is that I am trying to test it remotely. I want an app to be able to call the service from another server/domain.
I'm thinking it has something perhaps to do with the config files. Here is the config file of my service project.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<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>
It is not as simple as that. WCF works with the SOAP protocol, you can't 'just' pass the method name and the value in the Url.
You can use a Restfull-API, I am referring you to this awsome post that tells all about it in a simple and concise manner.