i am new to windows 8 metro application development , please let me help out in figuring out this issuse.
i want to consume web services in my metro application but the service reference url is dynamic.
i my app , the user will be given a provision to specify the url in a textbox , so i need to connect to that web service , that means the service reference url will be changing.
Till now i am connecting to web service in a traditional way like , giving a specific service reference by adding service reference and creating an instance and using that instance to call all the methods inside that web service .
but,
1) how should i consume web services if the service reference url is changing.
2)Access individual service methods inside that service (call that methods by passing some parameters as inputs).
Thanks in advance.
If you have the same service with different locations simply add it with "Add Service Reference..." and add the specified URL in the service client constructor:
var svc = new DataServiceClient("BasicHttpBinding_DataService",
"http://url.com/DataService.svc");
BasicHttpBinding_DataService is your (generated) binding name from the client config (automatically generated when doing "Add new Web Reference..."):
Example ServiceReferences.ClientConfig
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_DataService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:44300/Services/DataService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DataService"
contract="DataService.DataService" name="BasicHttpBinding_DataService" />
</client>
</system.serviceModel>
</configuration>
The code above can be used to change the address (e.g. https://localhost:44300/Services/DataService.svc) to one generated at runtime...
And have a look at this: http://blog.rsuter.com/?p=281
Related
I trying host my project, but when I run svc file then i get exception.
Exception data: System.InvalidOperationException: The convention requires the use of Session, but the "BasicHttpBinding" binding is not supported or is not configured correctly.
What could be the problem?
I tried changing the web.config file but I don't know what the problem is
You can change your binding mode from BasicHttpBinding to WsHttpBinding. Since the default binding method for HTTP is BasicHttpBinding, you can modify it in the <System.ServiceModel>:
<protocolMapping>
<add scheme="http" binding="wsHttpBinding" bindingConfiguration="WsHttpSession"/>
</protocolMapping>
This allows you to modify the binding.
I've two separate tables to log user activity and errors in asp.net web Api.
Here's my Activity Log table:
To store the Log information in the table, Here's the Nlog.config setting.
<target name="database" xsi:type="Database" keepConnection="true" useTransactions="true"
dbProvider="System.Data.SqlClient" commandType="Text"
connectionString="data source=XXXXX;initial catalog=XXXXX;integrated security=false;persist security info=True;User ID=XXXXX;Password=XXXXX"
commandText="INSERT INTO [dbo].[ActivityLog]([PageName],[MethodName],[IPAddress],[RequestedUrl],[IsAuthenticated],[UserName],[Date]) VALUES(#PageName,#MethodName,#IPAddress,#RequestedUrl,#IsAuthenticated,#UserName,#Date)">
<parameter name="#PageName" layout="" />
<parameter name="#MethodName" layout="" />
<parameter name="#IPAddress" layout=""/>
<parameter name="#RequestedUrl" layout="${aspnet-request:serverVariable=HTTP_URL}"/>
<parameter name="#IsAuthenticated" layout="${aspnet-user-identity}:isAuthenticated"/>
<parameter name="#UserName" layout="${aspnet-user-identity}"/>
<parameter name="#Date" layout="${date:s}"/>
</target>
For the Page Name parameter I need the Web API Controller Name, and for Method Name parameter I need the action Method of the Controller that is called.
Also I need to know whether the user is authenticated or not.
Now Kindly let me know the settings defined in the Nlog config file are correct or not and also how to pass values to the other parameters.
All possible layout renderers could be found here.
You could use the following renderers:
Web API Controller Name: ${aspnet-MVC-Controller}
Method Name: you could use the ${callsite} or ${aspnet-mvc-action}
isAuthenticated: ${identity:isAuthenticated}
PS:
All parameters to the database target are string parameters
The binding at system.serviceModel/bindings/webHttpBinding does not have a configured binding named 'webBinding'. This is an invalid value for bindingConfiguration.
there is a problem with your config, possibly you are trying to use webHttpBinding but didn't define any bindingConfiguration named webBinding in the bindings section.
something like -
<webHttpBinding>
<binding name="webBinding">
</binding>
</webHttpBinding>
I have configured Tomcat 6 with in-memory session replication. I am also using IIS 7 (I know, I know) and the AJP connector via isapi_redirector. The cluster is working properly and I am able to replicate session attributes using the SessionExample in the examples war. The problem is that I am unable to do the same in my custom application. I have added the distributable tag to the web.xml file on both servers in my test cluster. However, I don't see any message in the logs mentioning the attributes getting sent to the cluster (I see them for SessionExample). The only primary differences that I can see in my app from the examples:
The examples war uses servlet 2.5. I am still required to use 2.4.
My application uses SSO and requires the user to login.
The application is a portal application.
Also, in the code of the application, I am setting a simple string in the attribute, so nothing fancy.
So, I was wondering if anyone has some tips to get this working?
Thanks
Here is the cluster section within of my server.xml:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="6">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.104"
port="45564"
frequency="500"
dropTime="10000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="7000"
maxThreads="6"
timeout="15000"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"
timeout="70000"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/apache-tomcat-6.0.37/war-deploy/war-temp/"
deployDir="/apache-tomcat-6.0.37/webapps/"
watchDir="/apache-tomcat-6.0.37/war-deploy/war-listen/"
watchEnabled="true"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
Sorry. I found the issue. I was expecting to see messages in the log regarding the creation of the session attributes. I didn't realize that the examples project had a session listener that was outputting the messages to the log. I was thinking that it was simply from the log level that I had set.
Thanks to anyone who read this post.
This question already has answers here:
The type 'RestService.weddingservice', provided as the Service attribute value in the ServiceHost directive could not be found
(6 answers)
Closed 7 years ago.
The error is:
The type 'WF.XXX.WebServices.XXXXService', provided as the Service
attribute value in the ServiceHost directive, or provided in the
configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations could
not be found.
Stack Trace:
[InvalidOperationException: The type 'WF.XXX.WebServices.XXXXService',
provided as the Service attribute value in the ServiceHost directive,
or provided in the configuration element
system.serviceModel/serviceHostingEnvironment/serviceActivations could
not be found.]
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String
constructorString, Uri[] baseAddresses) +52742
System.ServiceModel.HostingManager.CreateService(String
normalizedVirtualPath) +1459
System.ServiceModel.HostingManager.ActivateService(String
normalizedVirtualPath) +44
System.ServiceModel.HostingManager.EnsureServiceAvailable(String
normalizedVirtualPath) +623
[ServiceActivationException: The service
'/XXXXX/XXXXXService/XXXXService.svc' cannot be activated due to an
exception during compilation. The exception message is: The type
'WF.XXX.WebServices.XXXXService', provided as the Service attribute
value in the ServiceHost directive, or provided in the configuration
element
system.serviceModel/serviceHostingEnvironment/serviceActivations could
not be found..] System.Runtime.AsyncResult.End(IAsyncResult result)
+687598 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult
result) +190
System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult
ar) +304662
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult
ar) +94
How to fix this error on the server?
Update on 9/18/2012:
I have Visual Studio 2012 and .NET Framework 4.5 installed on my machine but server has only .NET Framework 4.0. I am not sure if this matters, because I built the service with .NET Framework 4.0.
But strangely, I noticed a 4.5 feature when I run my project. It shows a URL to singleWSDL file, which is not available in .NET 4.0 version. Why does this show up when the project is built with .NET Framework 4.0? Here is the screenshot:
Update 9/19/12:
Here is the relavant web.config file:
<system.serviceModel>
<services>
<service name="XXXXService">
<!-- Use a bindingNamespace to eliminate tempuri.org -->
<endpoint address="" name="XXXXService"
binding ="basicHttpBinding"
bindingNamespace="#services.url#/XXXXService"
contract="WF.XXX.WebServices.XXXXService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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"/>
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="None" mapClientCertificateToWindowsAccount="true" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
To answer your questions
(1) Make sure you have built your project and the the dll which contains the service type XXXXService is placed in the bin directory.
(2) Single Wsdl is a new 4.5 feature. Since 4.5 is an in-place upgrade of 4.0 you will get the benefit of ?SingleWsdl even if you target your project to 4.0. But when you deploy the same service on a machine with just 4.0 then you will not be able to get this. To get this on your service machine make sure you have 4.5 on that too.
Hope this helps.
Thanks!
I had the same problem and the cause was that I had changed the namespace in the code files IService1.cs and Service1.svc.cs but forgot to change the namespace in the Service1.svc file.
E.G. in service1.svc
< % # ServiceHost Service="WcfService2.Service1" % >
must be changed to:
< % # Service="NewNamespaceName.Service1" % >
You can build the solution without Visual Studio catching the typo error.
I had the same issue. In my case, simply deleting the bin and obj folders and rebuilding fixed the issue.