I'm building a Web API to access my database. I would like to create a Single Page Application Website first then a iPhone, Android and Windows application. Classic.
My data and business layer are already finished.
1. First I decided to build a Json WCF Webservice. In Visual Studio I created a WCF Service Application. I modified the Web.config file to accept Json requests and implemented my interface and svc file.
2. After that I discovered ASP.NET Web Application with the Web API template. So I decided to change and to create a real web API with this full website structure.
Now I'm lost. What are the differences between these two possibilities to create a Json Web API? What is the best one and for what reason?
I am need of some details help with this project:
The desired goal:
1. Create a service running in a website that will use the website's ASP.NET SQL Provider membership (in the website) to authenticate the calling client.
2. Create a windows forms client that calls the service providing a username and password that is in the website membership database to authenticate consumption of the service.
3. Configure the service and client in a way to to secure messages, usernames and passwords during the authentication and service consumption.
I have used several tutorials to create the service and client but have not found one that my scenario. I have used http://msdn.microsoft.com/en-us/library/cc949082.aspx[^] which creates a web service not a website with a service. But, it is close so that is my tutorial for now. Most of my issues are in the web.config and app.config files for the service and client and of course with the whole topic of certificates.
I started out just getting a simple service client working to verify my approach
1. I run the website with the service in debug mode using Visual Studio Web Developer 2010 Express - thus the website with the service runs in localhost.
2. I build a windows form client (in the same machine) and add a service reverence using the url of the service running in localhost. Every time I change anything in the service, I delete and then add the service reference to redo the app.conf file.
OK, So far all is working for simple behaviors and bindings but when I try to build a service using membership for authentication - I get numerous errors.
After many days of reading and trying, I have a service to use membership as the authentication that I think is working and it includes a certificate I think is set up correctly. Here is the web.config services config. Note that the references to provider "AspNetSqlMembershipProvider" are correct and double checked.
<!-- Below gave a keyset does not exist error until I used WSE
C:\Program Files\Microsoft WSE\v2.0\Tools\Certificates\WseCertificate2.exesdc
Opened the certificate and gave permission to Dennis_win7/Dennis and Everyone -->
<!-- <serviceHostingEnvironmentmultipleSiteBindingsEnabled="true"/> -->
I start the website in debug mode and the site shows up in a browser at http://localhost:58139/MyWebService/service.svc and the page displays as expected - thus the service is running and seems to like the certificate.
I have included a user dan in the membership with password dan123 and checked that that user can login to the server (ASP.Net Login control) The user is in the membership database.
Now to the client. I used Visual Studio 2012 Express to create the windows forms client. I add the service reference which creates an entry in the app.config file. Here is the entry that is added when I add the service reference.
PrivateSub Btn_CallService_Click(sender AsObject, e As EventArgs) Handles Btn_CallService.Click
TB_Serviceresponse.Text = ""Dim gethello As MyServiceReference.ServiceClient
gethello = New MyServiceReference.ServiceClient
' the Web Site Membership has the following user in the SQL Membership
' I can login to the membership on the website useing this user
' If the username is not set then the service gives an error
' " The username is not provided. Specify username in ClientCredentials."
gethello.ClientCredentials.UserName.UserName = "dan"
gethello.ClientCredentials.UserName.Password = "dan123"
' TB_Serviderespone is a textbox for the service response
TB_Serviceresponse.Text = gethello.SayHello()
When I run the client and do not set username and password I get an error
"The username is not provided. Specify username in ClientCredentials." That seems to indicate the service is expecting the username password - that is good - right?
When I run the client and set the username and password I get the following error at the gethello.Open() statement:
An unhandled exception of type 'System.ServiceModel.Security.SecurityNegotiationException' occurred in mscorlib.dll
Additional information: SOAP security negotiation with 'http://localhost:58139/MyWebService/Service.svc' for target 'http://localhost:58139/MyWebService/Service.svc' failed. See inner exception for more details.
I do not know how to see the inner exception.
Am I missing something the the client app.config - certificate info or ?
looking at this site I tried various things but still no success.
I am sooooo close to getting this to work!
Can anyone point me to a solution? Any ideas will be much appreciated.
perhaps I don't have a certificate set up for the client correctly or some missing info in app.config file for the client.
say for i have one service class in code and one contract in code so then can we have multiple service tag in config file which will point my single service & contract.
my intention is not to expose my all endpoints details to client
here i am giving a code just to explain well what i am trying to achieve.
in the above config i define two service tag with same name because my service full name with namespace is CustomService.BusinessLayer
is it ok or do i need to give unique name for each service tag?
my intention is i will have same service but with multiple service tag and when customer will add my service reference at their end from VS IDE then they will not be able to see all my service endpoint.
my intention is not expose all endpoint & address to every client.
so guide me what i have done does it work or not....if not then rectify my config entry and tell me how could i restrict my endpoint not to expose each binding & address before all client.
just see this config entry can we give any name to service ? or is it mandatory to give the name of my service class including namespace ? please discuss with sample code and config entry. thanks
And i am expecting a response from this method. But it seems like ComplexType object can only be passed in POST or PUT method not in GET method based on few article in web.
But i want an array result from the above method as response.
Could any one help me how the UriTemplate can be assigned to the above method.?
And how to pass JsonInput Parameter to this REST method from c# client application and how to parse the result back to double type at client side.?
If there is any alternative way of getting response from rest json method, pls suggest me..
I have tried an exhaustive number of solutions and I keep coming up short.
What I need is an Xbap application that is hosted by IIS 7 which can consume a WCF service hosted on the same server as the Xbap. I have tried hosting the WCF service by self hosting it in a Windows Service (apparently this is no good for partial trust) and I have tried hosting the WCF service in IIS. I have tried getting the WCF service to host in IIS by both adding a new web site to my solution and by adding a WCF Web Application to my solution. Neither have produced the results I need.
Unfortunately, Full Trust and Certificates are NOT an option.
I presently have the Xbap and WCF service running in the same application under the Default Web Site within IIS on my development server.
When I do this I am able to run the Xbap and the application communicates with the WCF service without a problem. The moment I go to a client machine on the local Intranet I get Trust issues. I know I must be doing something fundamentally simple wrong. However, after watching a variety of tutorials and reading countless articles I cannot correct the problem.
Here is the web.config file within my WCF Web Application
<?xmlversion="1.0"encoding="utf-8"?><configuration><system.web><compilationtargetFramework="4.0"/></system.web><system.serviceModel><bindings><basicHttpBinding><bindingname="DefaultBinding"/></basicHttpBinding></bindings><behaviors><serviceBehaviors><behavior><!-- To avoid disclosing metadata information, set the value below to false before deployment --><serviceMetadatahttpGetEnabled="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 --><serviceDebugincludeExceptionDetailInFaults="false"/></behavior></serviceBehaviors></behaviors><serviceHostingEnvironmentmultipleSiteBindingsEnabled="true"/><services><servicename="SMService.SMService"><endpointaddress=""binding="basicHttpBinding"bindingConfiguration="DefaultBinding"contract="SMService.ISMService"/></service></services></system.serviceModel><system.webServer><modulesrunAllManagedModulesForAllRequests="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.
Here is my client Xbap
///<summary>/// Interaction logic for Page1.xaml
///</summary>publicpartialclass Page1 : Page
remoteAddress = new Uri(System.Windows.Interop.BrowserInteropHelper.Source, "SMService.svc");
client = new SMService.SMServiceClient(new BasicHttpBinding(), new EndpointAddress(remoteAddress));
privatevoid btnGetMessage_Click(object sender, RoutedEventArgs e)
lblResponse.Content = client.GetMessage(txtMessage.Text);
As I said before when I run it from the development server everything works.
As soon as I go to a client machine I get a Trust Not Granted Exception with the following details:
PLATFORM VERSION INFO
Windows : 6.1.7601.65536 (Win32NT)
Common Language Runtime : 4.0.30319.18444
System.Deployment.dll : 4.0.30319.18408 built by: FX451RTMGREL
clr.dll : 4.0.30319.18444 built by: FX451RTMGDR
dfdll.dll : 4.0.30319.18408 built by: FX451RTMGREL
dfshim.dll : 4.0.41209.0 (Main.041209-0000)
* Online only application.
* Browser-hosted application.
Below is a summary of the errors, details of these errors are listed later in the log.
* An exception occurred while determining trust. Following failure messages were detected:
+ User has refused to grant required permissions to the application.
* An exception occurred while downloading the application. Following failure messages were detected:
+ The AssertApplicationRequirements method failed. The application cannot be committed.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
There were no warnings during this operation.
OPERATION PROGRESS STATUS
No phase information is available.
Following errors were detected during this operation.
* [9/24/2014 12:09:06 PM] System.Deployment.Application.TrustNotGrantedException (Unknown subtype)
- User has refused to grant required permissions to the application.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.ApplicationTrust.RequestTrust(SubscriptionState subState, Boolean isShellVisible, Boolean isUpdate, ActivationContext actCtx, TrustManagerContext tmc)
at System.Deployment.Application.DeploymentManager.DetermineTrustCore(Boolean blocking, TrustParams tp)
at System.Deployment.Application.DeploymentManager.DetermineTrust(TrustParams trustParams)
at System.Deployment.Application.InPlaceHostingManager.AssertApplicationRequirements(Boolean grantApplicationTrust)
at MS.Internal.AppModel.XappLauncherApp.AssertApplicationRequirementsAsync(Object unused)
* [9/24/2014 12:09:06 PM] System.Deployment.Application.DeploymentException (Unknown subtype)
- The AssertApplicationRequirements method failed. The application cannot be committed.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.DeploymentManager.SynchronizeCore(Boolean blocking)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.
Any help, insights, or suggestions would be greatly appreciated. I'm sure it's something simple. However, it's escaping me and I need to start making progress.
I'm trying to bring a WCF Service from IIS Express to IIS 8. On IIS Express everything works fine. On IIS 8 I have some problems in downloading files. When I try to download a file (such as Stream) I get the following error:
The content type application/zip of the response message does not match the content type of the binding (text/xml; charset=utf-8). If you are using a standard encoder, check that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were.......
I am struggling to get out from this exception. I don't know why it is thrown always. My service( server) installed correctly from insaller and it is running in the background. But server has exposed the end points in a way:
But as soon as I send test data after opening the service, to the very first end point exposed by server. it throws the following exception
There was no at net.tcp://localhost:8732/PlcInputService a listening endpoint available that could accept the message. This is often caused by an incorrect address or SOAP action. For more details, see "InnerException", if any.
When you self-host, the endpoint must be created by the code that is running the service. The configuration is not used because you are not running your WCF code within ASP.NET or IIS then -- it is standalone.
Hi, based on recommendations on this forum, I made a wcf application to serve my 2 applications that need data.
So my solution looks like this now:
Data Access Layer project
wcf service library project
viewmodel project that extracts data from the wcf service library
a wpf application that binds to viewmodels from the viewmodel project
a test app that tests the wcf service & models
a web app that provides input for some of the models
The unit tests I made to test the wcf works perfectly as long as the service is up and running.
The wpf application fails to run as soon as I try to use the wcf service though. Always same thing: can't find the endpoint.
So when I use the models in the test app, everything works fine, when I use the same models in my wpf app, they throw exceptions as soon as they contact the wcf service. Same problem when my webapplication does this.
Can someone help me out please?
InvalidOperationException happens in following code when I call the constructor of the client:
InstanceContext context = new InstanceContext(this);
client = new LezingenServiceClient(context, "lezingen");
bij System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
bij System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
bij System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
bij System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
bij System.ServiceModel.DuplexChannelFactory`1..ctor(Object callbackObject, String endpointConfigurationName, EndpointAddress remoteAddress)
bij System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
bij System.ServiceModel.ClientBase`1..ctor(InstanceContext callbackInstance, String endpointConfigurationName)
bij System.ServiceModel.DuplexClientBase`1..ctor(InstanceContext callbackInstance, String endpointConfigurationName)
bij Model.LezingenService.LezingenServiceClient..ctor(InstanceContext callbackInstance, String endpointConfigurationName) in d:\Programmeren4\TaakLezingen\Model\Service References\LezingenService\Reference.cs:regel 626
bij Model.CursistDepository..ctor() in d:\Programmeren4\TaakLezingen\Model\CursistDepository.cs:regel 33
Configuration files below:
app.config of service library project:
<?xmlversion="1.0"encoding="utf-8"?><configuration><configSections></configSections><connectionStrings><addname="LezingenService.Properties.Settings.home"connectionString="Data Source=localhost;Initial Catalog=Programmeren4_TaakMVVM;Integrated Security=True"providerName="System.Data.SqlClient"/></connectionStrings><appSettings><addkey="aspnet:UseTaskFriendlySynchronizationContext"value="true"/><addkey="ClientSettingsProvider.ServiceUri"value=""/></appSettings><system.web><compilationdebug="true"/><membershipdefaultProvider="ClientAuthenticationMembershipProvider"><providers><addname="ClientAuthenticationMembershipProvider"type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=220.127.116.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35"serviceUri=""/></providers></membership><roleManagerdefaultProvider="ClientRoleProvider"enabled="true"><providers><addname="ClientRoleProvider"type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=18.104.22.168, Culture=neutral, PublicKeyToken=31bf3856ad364e35"serviceUri=""cacheTimeout="86400"/></providers></roleManager></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. -->
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<!-- 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 -->
we are developing an mobile application and we have used WCF service to fetch SQL Server data through online.
We are trying to authenticate each WCF Service call(server) by passing headers from client (mobile application). For this we have generated a token and passed the same in headers of each client call.
We have stored the tokens in HttpRuntime.Cache. But after few minutes [in idle mode] the cache entry is cleared.
Note: If continuously server and client communicates, it works perfectly.
I am calling a wcf service that returns a complex type response. How can i get that response and cast into some array list or string array to iterate the items. or is there any other way i can get complex type reponse?
I'm new in WCF.
And I would like to create a web site using WCF + JQuery.
What I have in mind is to have
JQuery + HTML5 as my Presentation Layer
WCF as Web Services that connect with JQuery
Dll as Business Logic Layer which work with WCF
EF6 as Data Access Layer
MSSQL as Database
Is this the way to do it?
Or to have everything inside WCF and remove the dll and Ef6?
From what I've read thus far, I think that WCF can achieve this. I'm just trying to wrap my head around the best option within WCF to use.
My servers and many clients are on the subnet 10.0.1.NNN, and other clients are on 10.0.2.NNN, 10.0.3.NNN, 10.0.4.NNN, 10.0.5.NNN, and 10.0.6.NNN. Every client has a static IP (no DHCP).
From what I presently understand, the P2P mesh option in WCF would not work in this, as the mesh option seems only to work within the same subnet. Correct me if I'm wrong.
In short, I'm in search of a "push" methodology vs. my present "pull" methodology. That being, the server "pushes" data to the client dynamically (when the data arrives at the server) vs. the client "pulling" the data from the server via a .NET timer being fired every NN minutes by 60+ workstations, with each workstation having 5+ apps running. That's 3500+ hits on the database per hour. A push method would reduce this to about 400 hits/hour.
What I currently conclude the option to be is that each client registers that it is "available" to receive msgs from the server. The server, when it receives data from another server activity, it needs to send info/data to the client. The client gets the data and takes appropriate action.
1) Do I need to "register" the client is available to receive msgs/data from the server? Candidly, I'd prefer to say away from "registering"/"unregistering".
2) Or, can the client merely have a WCF [server] channel open and the server check to see if that client's WCF channel is open to then send a msg/data? Note: The msg/data from the server to the client needs only be one-way.
Separate, though similar:
We do have a Chat app that uses older TCP/IP methods (.NET 1.1 dayz....) and does register/unregister with a main server.
I'd prefer to change it so that when the client chat app is opened, it can query to see which other clients are open to list as being "available" to chat with.
The good thing in both of these above is that we have a separate VMS-based system that everyone "logs" into (via a windows app or terminal via a windows telnet app) at the beginning of the day. This system identifies which IP address a given staff person is at. We can query this system in Windows to find out who is at which IP address, including multiple IP addresses.
As such, Windows (.NET) can get a list of "active" staff/IP addresses and then check those specific IP addresses for any WCF services available to connect into. OR so, I'm hoping is possible within WCF.
From what I've learned thus far of WCF, I prefer to do the entire binding in code and not via some .config file with each client.
I appreciate any insight y'all might have. TIA
Last Visit: 31-Dec-99 19:00 Last Update: 25-Dec-14 22:45