We have a silverlight project that uses RIA services. There is some code that I want to share between that project and a web service. I have to leave the code where it is now, i.e. I cannot share the code.
What I thought would be good is for the web service to call the RIA service. It will be sitting on the same server.
I went to my web service project, and added a service reference to the ria service. I clicked advanced and ticked the option for it to 'generate asynchronous operations'.
I thought it would be all good to go, but I got some warnings. The client code that it generated was missing any actual code relating to the asynchronous calls, and the app.config is also empty. Here are the warnings,
Warning 2 Custom tool warning: Cannot import wsdl:binding
Detail: 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='CarServiceSoap']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='BasicHttpBinding_CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap 1 1 CarTransmitter.Core
Warning 3 Custom tool warning: Cannot import wsdl:port
Detail: 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_CarServiceSoap']
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:service[#name='CarService']/wsdl:port[#name='BasicHttpBinding_CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap 1 1 CarTransmitter.Core
Warning 1 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Referenced type 'CarData.Organisation, CarData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' with data contract name 'Organisation' in namespace 'http://schemas.datacontract.org/2004/07/CarData' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='CarServiceSoap'] C:\Develop\DotNet\Trunk\Applications\WcfServices\CarTransmitter\CarTransmitter.Core\Service References\CarService\Reference.svcmap 1 1 CarTransmitter.Core
Use the RIA services project option to create your service library. That creates 2 projects that are bound together (for code gen of the proxy objects). Both are effectively just libs (1 Silverlight and 1 .Net)
Link any RIA services client library to you Silverlight app. Then link the .web RIA project to your hosting web app (for the standard RIA use). You can also add the .web library to your Wcf service as a .Net lib (not consume it as a service).
If you did not create your main Silverlight project as a RIA services project you will need to move the settings across from the app.config file to your web.config file. If you already have the service support settings you only need to copy the db connection string across. The db connection string only should be needed for you Wcf project.
You should then be able to either use the server-side RIA calls (don't forget to add your own submitchanges calls as RIA does that behind the scenes once per batch of updates), or just use the data layer (EF etc) directly.
Not finished completely, got quite a bit further along. The problems I am having now warrant a new question.
The solution to the above problem is to untick the option 'reuse types in referenced assemblies'. When you add service reference, you click the advanced button and you get the option 'reuse types in referenced assemblies'.
This is because I am sharing some code between the two projects I am using, and it was trying to 'reuse' objects I had on my side in the shared code. Instead I just wanted it to create proxy objects for me and not reuse those objects.
Yes. It is possible to do.
Create a library project
Add LINQ to Entity model
Add public class DomainService1 : LinqToEntitiesDomainService
Check if your web.config looks like this one
[?xml version="1.0"?]
[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]
[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=31BF3856AD364E35" /]
[/modules]
[/system.webServer]
[system.serviceModel]
[domainServices]
[endpoints]
[add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /]
[add name="soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /]
[add name="JSON" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /]
[/endpoints]
[/domainServices]
[serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /]
[/system.serviceModel]
[connectionStrings]
[add name="ASPNETDBEntities1" connectionString="metadata=res:///Model1.csdl|res:///Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=ASPNETDB;persist security info=True;user id=sa;password=yourpassword;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /][/connectionStrings]
[system.web]
[compilation debug="true"][assemblies][add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /][/assemblies][/compilation]
[/system.web]
[/configuration]
Do WEB Publishing locally and test service link.
Enjoy!
Related
I have custom sections in my project. The following line works for my Web API project from the web.config:
...
<sectionGroup name="Project.Models">
<section name="product" type="Project.Models.Configuration.ProductSettings" />
</sectionGroup>
</configSections>
<Project.Models>
<product id="1" />
</Project.Models>
When I run my unit tests, I get the following error:
System.Configuration.ConfigurationErrorsException : An error occurred creating the configuration section handler for Project.Models/product: Could not load type 'Project.Models.Configuration.ProductSettings' from assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not load type 'Project.Models.Configuration.ProductSettings' from assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Why do I have to specify the assembly name when referencing this from my unit tests app.config? This resolved the issue, but not sure why it's needed.
<section name="product" type="Project.Models.Configuration.ProductSettings, Project.Models" />
It depends on the host that executes your code.
Without extra plumbing you'll find that in the inner workings of the Configuration namespace the type attribute is fed into the static method Type.GetType(string typeName).
For the typeName parameter you'll find in its description:
If the type is in the currently executing assembly or in Mscorlib.dll, it is sufficient to supply the type name qualified by its namespace.
The key part is currently executing assembly. That seems to be never the case for normal appdomains, and thus for the application that runs your unit-test (which I assume is VS).
The ASP.NET web hosting on the other hand provides an internal HttpConfigurationSystem class that re-implements the calls to GetSection. It is a little hard to follow but it looks like an internal class BuildManager loads all assemblies and iterate over all types, to find one that matches.
This explains the difference in behavior. It is adviced to always specifiy the assemblyname. In the asp.net scenario, if the assemblyname is present in the type parameter it short-circuits to the Type.GetType call which prevents the loading and inspection of all dll's in the bin folder of your webapp.
first of all, I would like to say that I have tried to resolve this issue for several hours through trying a bunch of different approaches from people that had the same issues, but to no avail. I am pretty clueless at this point.
I am using MySql.Data and MySql.Data.Entity dlls (version 6.7.4) which I have referenced in my ASP.NET 4.5 application.
I have managed to connect (locally) to my database and query it without a problem.
SqlConnection = new MySqlConnection("server=localhost;User Id=;Password=;database=;");
The problem is within a medium trust shared environment.
I get the following error (when attempting to connect to the database):
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
I have also tried to add "Integrated Security=True;includesecurityasserts=true;autoenlist=false;" to the connection string, but didn't help.
I have also tried to add this in my web.config:
<mscorlib>
<security>
<policy>
<PolicyLevel version="1">
<SecurityClasses>
<SecurityClass Name="MySqlClientPermission" Description="MySql.Data.MySqlClient.MySqlClientPermission, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</SecurityClasses>
<NamedPermissionSets>
<PermissionSet class="NamedPermissionSet" version="1" Name="ASP.Net">
<IPermission class="MySqlClientPermission" version="1" Unrestricted="true">
</IPermission>
</PermissionSet>
</NamedPermissionSets>
</PolicyLevel>
</policy>
</security>
But that did not work either.
I have then tried to add a bunch of PermissionSets, IPermissions and what not in the web.config by following some articles, but that didn't seem to work for me.
Please note:
Setting trust level="Full" in the web.config is not an option.
The connection string that I use to connect to the database is not in my web.config, and I would like to keep it that way.
Using anything else than MySql is not an option.
Any and all help is appreciated! Thank you!
EDIT
I have changed the way I communicate with the database with an ODBC connection.
Works properly using full trust, but as soon as I change to medium trust, I get basically the same error as with MySql connectors.
Request for the permission of type 'System.Data.Odbc.OdbcPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Can anyone please point me to the right direction, such as a full example on how you managed to make it work, because I can't seem to make this work using medium trust...
Thanks!
I ended up using an ODBC connection.
Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;Database=myDataBase; User=myUsername;Password=myPassword;Option=3;
http://www.connectionstrings.com/mysql-connector-odbc-5-1/remote-database/
I know you tried the following solution:
Change the security from the web config to full trust.
Use the bin deployment (Copy to Local for dll property).
Change the trust level from assembly.
and so many other but no one is working.
you can not deploy this on medium trust. It required full trust for proper working.
May be you are using the medium trust server for deployment. You need full trust for the deployment. Only solution is you need to run it on Full trust environment. You need to contact with your server support and change the trust level medium to Full.
Here is how I solved a similar issue with trying to get MySql to work in a medium trust environment.
We tried everything to the ‘book’ and simply could not get it to work!
Turns out the MySql connecter version is the key. Ask you web hosting company what version of the MySqlClient they have installed on their server in GAC.
(GAC simply means the library is installed on the server so that it can be referenced directly and without you having to upload the MySql.Data.dll to your bin folder. The latest installable version is available here: http://dev.mysql.com/downloads/connector/net/).
Once the driver is installed on the server in GAC you just need to reference it in your web.config like this, but replace Version=6.6.5.0 with your web hosting companies version:
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
</assemblies>
</compilation>
Problem
I'm getting the following error whenever I try to load out .svc url (Local)
Configuration binding extension 'system.serviceModel/bindings/pollingDuplexHttpBinding' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly.
Enviroment
The project was build by a ex colleague of mine, who I can't reach. It's a webservice build in .Net Framework 4
I get this error when I attempt to gain access to our .svc file
In the web.config I have this setting:
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="pollingDuplexHttpBinding" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement, System.ServiceModel.PollingDuplex, version=3.0.0.0, Culture=neutral" />
</bindingExtensions>
</extensions>
which is later used as <endpoint address="" binding="pollingDuplexHttpBinding" contract="<ourcompany>.DataService.IMessageService"/>
Attempts
In regards to other posts about this error I have already tried:
Installing Dot net 3.5 SP1
Removing the line from web.config
Reinstalled IIS
I have no idea what to do, or how to fix this.
The strange part is that it does work on our live server, but not on my own computer for testing purposes!
Refer - Unrecognized element 'pollingDuplexHttpBinding' in service reference configuration
<!-- Register the binding extension from the SDK. -->
<extensions>
<bindingExtensions>
<add name=
"pollingDuplexHttpBinding"
type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</bindingExtensions>
The difference here is, Version=4.0.0.0 and PublicKeyToken=31bf3856ad364e35.
You can get more information on the Section "To use PollingDuplexHttpBinding" section of - How to: Build a Duplex Service for a Silverlight Client.
Good luck. :)
When trying to run my code, I receive the following error:
CS0234: The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
I have included references to System.Data.dll and System.Data.OracleClient.dll, but I am still getting this error.
The error is being caused by the line using System.Data.OracleClient in my namespace declaration.
The using System.Data.OracleClient directive means that that namespace should be considered when trying to determine what non-full names mean.
Adding a reference, means you add a reference to a given assembly, in this case System.Data.OracleClient.dll. From VisualStudio, SharpDevelop or MonoDevelop you will see a references folder in the project explorer view. Right click and "Add Reference" (VisualStudio and SharpDevelop) or "Edit References" (MonoDevelop), and add in System.Data.OracleClient.dll
If using nant you'll need to edit your nant script.
Assemblies and namespaces overlap, but aren't quite the same. The reference means you can use e.g. System.Data.OracleClient.OracleDataReader because the project now knows what assembly the code for that lives in. The using directive means you need only type OracleDataReader. There tends to be a heavy match between assemblies and namespaces because that makes life easier for everyone, but there are both times when an assembly has classes from more than one namespace, and when a namespace is split over more than one assembly. A classic example is that mscorlib has a lot of classes from System, System.Collections, System.IO etc. that you couldn't really hope to build a .NET project without (including some that .NET uses itself), while System.dll has a bunch more from exactly the same namespaces that you could feasibly get by without using (but you still will 99% of the time).
Unless you're writing an absolutely massive library though, with thousands of classes covering overlapping use-cases, your own assemblies should work with a single namespace - or at most a single one with some other namespaces within that one, like JaredksGreatCode having JaredksGreatCode.UserInterface within it - per single DLL.
The following worked for me:
Visual Studio --> WEBSITE --> Add Reference... --> Framework --> System.Data.OracleClient [check this option]
I had to add a reference to the Oracle.DataAccess.dll, and then I had to manually associate all the references to OracleClient.blahblah with
Oracle.DataAccess.Client.blahblah.
Hopefully this helps someone else.
Add a reference into your web config file as shown below. This works for me.
<!--REFERENCES-->
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
You add reference on System.Data.OracleClient.dll.
I have a functioning Silverlight 4 application (VS2010, SL4, WCF RIA, hosted on my dev box using Cassini, 64-bit Windows 7). Inside the ClientBin directory I have an .svc file that describes my service:
<% #ServiceHost Service="MyApp.Services.MyService
Factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory" %>
When I browse to http://localhost:52878/ClientBin/MyApp-Services-MyService.svc I see the following:
You have created a service. To test
this service, you will need to create
a client and use it to call the
service. You can do this using the
svcutil.exe tool from the command line
with the following syntax:
svcutil.exe http://localhost:52878/ClientBin/MyApp-Services-MyService.svc?wsdl
I want to access that service from a Windows Service application. My understanding is that I need to enable SOAP end-points in order to make this happen. So, I add the following to my web.config file:
<domainServices>
<endpoints>
<add name="soap"
type="System.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory,
System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</endpoints>
</domainServices>
Firstly, Intellisense complains about the presence of the tag, saying:
The element system.ServiceModel has
invalid child element domainServices.
Secondly, the aforementioned Silverlight application stops working, presumably because this change breaks the underlying web services.
Thirdly, it appears that the System.ServiceModel.DomainServices.Hosting assembly doesn't actually contain the SoapXmlEndpointFactory type; if I try to browse to the service after adding the above to web.config I see:
Could not load type
'System.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory'
from assembly
'System.ServiceModel.DomainServices.Hosting,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'.
If I inspect the assembly using Reflector, I see that it contains the DomainServiceEndpointFactory and PoxBinaryEndpointFactory types, but no SoapXmlEndpointFactory.
Could someone please let me know how I should be doing this? I can't believe that it should be this hard to simply consume a WCF RIA service in something other than a Silverlight application!
Instead of ...
System.ServiceModel.DomainServices.Hosting
use the assembly ...
Microsoft.ServiceModel.DomainServices.Hosting
from the WCF RIA Services toolkit. It contains the type SoapXmlEndpointFactory.
The default location is ... %Program Files%\Microsoft SDKs\RIA Services\v1.0\Toolkit\Libraries\Server
Have you tried just executing
svcutil.exe
http://localhost:52878/ClientBin/MyApp-Services-MyService.svc?wsdl
Alternatively, have you installed the RIA Services toolkit?
http://www.microsoft.com/downloads/details.aspx?FamilyID=7b43bab5-a8ff-40ed-9c84-11abb9cda559&displaylang=en
It's required for SOAP and JSON endpoints
The SoapXmlEndpointFactory class is part of the
Microsoft.ServiceModel.DomainServices.Hosting
assembly, which is included in the Silverlight Toolkit.
See here
<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>
Declare this in the ConfigSections. It's important to include the sectionGroup correctly