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?
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 design AJAX – Enable WCF web services for our mobile application. Web service methods returns data in JSON format. We are observing delay in calling web services and binding it to mobile widget. The size of data in approximately 50K.
According to Code Project , we have applied changes to web.config file of WCF Web Service.
Similarly, following one of the stackoverflow question we are trying to increase message size. Now, problem is how we should apply changes to our current web.config file so that message size is increase. We are using default NET 4.0 setting. Also, do we need to define end point on our client web.config file. Can someone provide client side web.config?
Our current server web.config settings is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<identity impersonate="false" />
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<system.serviceModel>
<diagnostics performanceCounters="All"></diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<!--Increase WCF Performance-->
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<!--Increase WCF Performance-->
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000"/>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileWCFService.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileWCFService.Service1" behaviorConfiguration="MobileService.webHttpBehavior" />
</service>
</services>
</system.serviceModel>
</configuration>
Can anyone confirm if changes I applied is valid or not and mark it has confirm answers?
<system.serviceModel>
<diagnostics performanceCounters="All"></diagnostics>
<behaviors>
<endpointBehaviors>
<behavior name="MobileService.webHttpBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<!--Increase WCF Performance-->
<serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!--Increase WCF Performance-->
<bindings>
<webHttpBinding>
<binding name="webHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000"/>
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="MobileWCFService.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="MobileWCFService.Service1" behaviorConfiguration="MobileService.webHttpBehavior" bindingConfiguration="webHttp" />
</service>
</services>
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 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.
I've created and tested WCF service, everything works fine.
When I deployed to TEST environment and tried to open https://my.site/myapp/EnrollmentService.svc I've got the error message:
Could not find a base address that
matches scheme http for the endpoint
with binding
MetadataExchangeHttpBinding.
Registered base address schemes are
[https].
Internet showed me that I need to add some more configuration options:
http://www.codeproject.com/KB/WCF/7stepsWCF.aspx
I've added some settings to service web.config file. Now it looks like in the following way:
<system.serviceModel>
<services>
<service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
<endpoint
address="https://my.site/myapp/EnrollmentService.svc"
binding="basicHttpBinding"
bindingConfiguration="TransportSecurity"
contract="McActivationApp.IEnrollmentService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.IEnrollmentService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="McActivationApp.EnrollmentServicBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
Actually, I've added "bindings" section and specified it for my endpoint.
But this changed nothing...
Please advise, what I need to do. Thanks a lot!
P.S. Are there any differences in WCF service consuming from https and http resources?
When you want to expose your service only over HTTPS (site does not support HTTP at all) you can't use anything that is dependent on HTTP. Your current configuration exposes help page on HTTP and also mex endpoing (with wrong contract) on HTTP. So try this:
<system.serviceModel>
<services>
<service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" contract="McActivationApp.IEnrollmentService"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="McActivationApp.EnrollmentServicBehavior">
<serviceMetadata httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
You have got http metadata endpoint that should be changed to https as below.
<serviceMetadata httpsGetEnabled="True"/>
Also if not necessary you should remove the mex and https metadata endpoint from production as a best practice.
To fix the problem by allowing HTTP, you need to add a http binding in IIS:
Navigate to your site in IIS
Click 'Bindings...' in the Actions panel on the right.
Click 'Add'
Select 'http' and OK out.
Alternatively, you can prevent the problem by either deleting the line, or changing:
<serviceMetadata httpGetEnabled="True"/>
to:
<serviceMetadata httpsGetEnabled="True"/>