So I've created a WCF service application and hosted it on IIS7. It currently has a few test 'helloworld' methods. When I run it in my browser I get this screen:
Now the service itself works great, but how can I display the operations like this:
Thanks to marc_s for the link: http://www.dotnetcurry.com/ShowArticle.aspx?ID=399 which I've followed so my web config is now setup like:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServer.Service1">
<endpoint address="" binding="webHttpBinding" contract="WcfServer.IService1" behaviorConfiguration="HelpBehaviour" />
</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="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="HelpBehaviour">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension" />
</system.webServer>
</configuration>
However, this only works locally. When I publish to my server on IIS7 I get a 404 error page when I click on the help link. Does anyone know why this is, or has come across it before?
(Last bit was solved by running: aspnet_regiis.exe -iru)
If you have a WCF service with a SOAP binding, you're unfortunately out of luck: there's no way in WCF out of the box to get a listing similar to ASMX with all the services.
With REST binding (webHttpBinding) and .NET 4.0, you can have an automatic help page generated which lists the URI templates, the HTTP methods supported and so forth. You can also tweak that page to a certain degree.
In order to have that automatic help page generated, you need to define (and reference) an endpoint behavior:
<behaviors>
<endpointBehaviors>
<behavior name="HelpBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
Then reference that behavior from your webHttpBinding endpoint, and you're done.
Read all about it:
A Developer's Introduction to Windows Communication Foundation 4
Windows Communication Foundation 4.0 - New REST Features
Clients and the Automatic Help Page in WCF WebHttp Services
Related
Hi I am developing small application using WCF,MVC4 and angularJS. I am refering following URL
https://code.msdn.microsoft.com/AngularJS-Shopping-Cart-8d4dde90#content
When i tried to add service reference in my mvc application I am getting below error
Metadata publishing for this service is currently disabled.
I gave below url to access service.
http://localhost:55835/Service1.svc
When i tried I am getting error. I am unable to add service reference in my application. I am little worried about my web.config file. This is my web.config file.
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp helpEnabled="True"/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Can someone tell me something I am missing anything in config file?
Thank you in advance.
This problem is displaying because you are not enabling metadata.Metadata(wsdl document for your service code) is neccessary because your client will generate proxy class on the basis of your metadata(wsdl code). If you will not enable your metadata then your client will never know how to implement the same kind of code in its's proxy classes.And this can be enabled under servicemetadata tag under servicebehavior tag by setting httpGetEnabled to true.
Add this line of code under servicebehavior tag just after </endpointBehaviors> tag.(please do not include <behaviour> tag again)
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" httpGetUrl="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
I have imported an a wcf service and it is accessible from local host but when I use my public ip address i am unable to reach it.
This is the contents of my web.config file.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"
targetFramework="4.0" />
</system.web>
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="clearUsernameBinding"
type="WebServices20.BindingExtenions.ClearUsernameCollectionElement, ClearUsernameBinding" />
</bindingExtensions>
<!-- Add the inspector attribute as a behavior for displaying SOAP XML packets -->
<behaviorExtensions>
<add name="consoleOutputBehavior"
type="WcfService1.ConsoleOutputBehaviorExtensionElement, WcfService1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<bindings>
<clearUsernameBinding>
<binding name="myClearUsernameBinding"
messageVersion="Soap12" />
</clearUsernameBinding>
</bindings>
<behaviors>
<!-- Add the inspector behavior -->
<endpointBehaviors>
<behavior name="inspectorBehavior">
<consoleOutputBehavior />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="HelloWorldServiceBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="WcfService1.CustomUserNameValidator, WcfService1" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="HelloWorldServiceBehavior"
name="WcfService1.HelloWorldService">
<endpoint address=""
binding="clearUsernameBinding"
bindingConfiguration="myClearUsernameBinding"
contract="WcfService1.IHelloWorldService" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
I have a console app that is able to communicate with it but ONLY with localhost.
This is how I am able to get to it. It is running on port 14946 and have port forwarded that port to the computer that has the service running. It is hosted on IIS.
http://localhost:14946/HelloWorldService.svc?singleWsd
If I use : {publicIP}:14946/HelloWorldService.svc?singleWsd
I get a 500 internal error which means its a configuration issue but I can't seem to pinpoint what the problem is.
EDIT: I am now receiving this error.
The type 'WcfService1.HelloWorldService', provided as the Service attribute value in the ServiceHost directive could not be found. I am able to get to it over the web now but receiving this error now. In order to fix the previous error I had to: 1.) Go to add remove features 2.) Expand MS .NET Framework 3.) Flip on both HTTP and Non-HTTP activation for WCF
Thanks,
If you properly hosted it in IIS you can just remove the port in endpoint and access it directly, something like this: ( add virtual application if necessary )
http://<public ip>/HelloWorldService.svc?singleWsd
It is working in your localhost because it was hosted in IIS Express upon debug mode and automatically assigned that port.
I have been searching for hours, but I could not find the solution. I will explain briefly.
I am learning WCF Services. I have just created a service and browse it. Here is the config file:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="EmployeeServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="EmployeeServiceBehaviour" name="EmployeeConfiguration">
<endpoint address="http://localhost:2005/EmployeeService.svc" binding="basicHttpBinding"
bindingConfiguration="" contract="IEmployeeConfiguration" />
</service>
</services>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
When browse it from Visual Studio there seems no problem. It works perfectly.
Second, I am trying to publish it on IIS. What I am doing is this:
I publish the service to a folder and add this service to IIS.
I select port 3006 as a port.
Below its config file. Note that I also changed port inside config to 3006
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="EmployeeServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="EmployeeServiceBehaviour" name="EmployeeConfiguration">
<endpoint address="http://localhost:3006/EmployeeService.svc" binding="basicHttpBinding"
bindingConfiguration="" contract="IEmployeeConfiguration" />
</service>
</services>
</system.serviceModel>
<system.web>
<compilation/>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
And I am waiting to run smoothly but:
IIS gives me a blank page from Chrome
And HTTP 400 Bad Request from Explorer
Lastly, if I remove address part from config file everything works well. But other confused thing is that, on my other computer after above scenario(address provided) I can reach the service. So, I really tired of searching why this is working on one computer and not working on another one. Could someone explain it to me?
I know it is a bit longer, but I have to explain it clearly.
Thanks
According my searches, I should not provide an address.
msdn.microsoft.com/en-us/library/aa751792(v=vs.110).aspx
You must always use relative endpoint addresses for IIS-hosted service
endpoints. Supplying a fully-qualified endpoint address (for example,
localhost/MyService.svc) can lead to errors in the deployment of the
service if the endpoint address does not point to the IIS-application
that hosts the service exposing the endpoint. Using relative endpoint
addresses for hosted services avoids these potential conflicts.
I think this will solve your problem:
Add this endpoint to your service:
<endpoint address="mex" binding="mexHttpBinding"
bindingConfiguration="" contract="IMetadataExchange" />
And change the name attribute of the service to your service class's full name:
<service behaviorConfiguration="EmployeeServiceBehaviour"
name="Namespace.EmployeeConfigurationClass">
Hope that is enough
This may be of help. ive just spent over 2 hours trying to get this working. i use FF and its set as the default browser.
in FF it was adding a / on the end of my URL
http://services.tester.dev/VehicleFeedService.svc/
which returned a NetworkError: 400 Bad Request
however in IE or chrome, it doesnt put the / on the end and it works fine.
one thing to note.. even in FF which was giving me a 400 bad request, the ?wdsl did work
http://services.tester.dev/VehicleFeedService.svc?wsdl
it appears that the / was causing the issue
You can try fiddler and also try the svcTracer which may give you lot of debugging information on the top of it you can also use includeExceptionDetailInFaults=true flag on the server but its important to flag that its not always right to send this information to the client specially if client is an external entity. With this warning following is the hint how to use it.
<serviceBehaviors>
<behavior name="ServiceBehavior">
....
<serviceDebug includeExceptionDetailInFaults="true" />
....
</behavior>
</serviceBehaviors>
Happy debugging :)
I have a web service made in c# and I want to know how to register it in IIS for consumption from another app. I know how to consume it from the same solution but this isn't the same case. Searching the internet, I've only found how to register an app.
A web service is treated like any other website in IIS. Simply convert the site to an application and pick the appropriate .Net framework version.
After you have setup the website for web service you need to do some setting in your web.config. I guess you might be missing them
Add service to the web.config like following
<services>
<service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
</endpoint>
</service>
</services>
Also add service behaviour and endpoint behaviour
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
When I hit f5 it doesn't fire up my web browser with the end points exposed.
How do I get this behavoir with my service?
My web.config looks like:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
It won't. It should run the WCF Service hosting window if you set the project up as a WCF Service project. To view in your browser you'll need to manually browse to the address it's being hosted at.