I'm trying to use WCF 4 to set up a RESTful web service. I'd like the service to be accessible both using HTTP and HTTPS. By default the service is created with the following configuration which works for http but not https:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" />
</protocolMapping>
</system.serviceModel>
I can then turn on HTTPS for the service by changing the configuration slightly to this:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior>
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding >
<binding name="SecureWebBinding" >
<security mode="Transport"></security>
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add scheme="http" binding="webHttpBinding" bindingConfiguration="SecureWebBinding"/>
</protocolMapping>
</system.serviceModel>
My question is how do I get the service working with both?
You should try to create two separate end-points. For example,
<system.serviceModel>
<services>
<service name="MyNameSpace.MyService">
<endpoint address="https://www.example.com/MyService.svc"
binding="wsHttpBinding" bindingConfiguration="SecureWebBinding"
contract="MyNameSpace.IMyContract" />
<endpoint address="http://www.example.com/MyService.svc"
binding="basicHttpBinding"
contract="MyNameSpace.IMyContract" />
</service>
<bindings>
<webHttpBinding >
<binding name="SecureWebBinding" >
<security mode="Transport"></security>
</binding>
</webHttpBinding>
</bindings>
</services>
</system.serviceModel>
Related
I try to connect to another WCF server use proxy which using basicHttpBinding /customBinding for binding on my .net 4.0 but it doen't work :Server Error in '/' Application
my web.config file :
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ServicesSoap">
<security mode="Transport" />
</binding>
<binding name="ServicesSoap1" />
</basicHttpBinding>
<customBinding>
<binding name="ServicesSoap12">
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://Test.com/LineTest/services.asmx"
binding="basicHttpBinding" bindingConfiguration="ServicesSoap"
contract="Test.ServicesSoap" name="ServicesSoap" />
<endpoint address="https://Test.com//LineTest/services.asmx"
binding="customBinding" bindingConfiguration="ServicesSoap12"
contract="Test.ServicesSoap" name="ServicesSoap12" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpGetBinding="true"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<services>
<service name="WCFServerForMobile.WCFServerForAlineTest">
<endpoint name="ServerForAlineTest" contract="WCFServerForMobile.WCFServerForAlineTest" binding="wsHttpBinding" address="AlineTest" behaviorConfiguration="restBehavior"></endpoint>
</service>
</services>
</system.serviceModel>
</configuration>
`
Is there any way to solve that problem
httpGetBinding does not accept boolean but Binding. You should put your binding name instead.
Instead of:
<serviceMetadata httpGetEnabled="true" httpGetBinding="true"/>
Use:
<serviceMetadata httpGetEnabled="true" httpGetBinding="basicHttpBinding"/>
I have a problem to pass username and password through Castle Windsor register by using custom WCF authentication.
I have a Web service configuration like below :
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsSecureBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="defaultProfile" name="GS1.CSSM.XMLGenerate.WebService.Implementation.XMLGenerateService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsSecureBinding" name="wsSecureService" contract="GS1.CSSM.XMLGenerate.WebService.Interface.IXMLGenerateService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="defaultProfile">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="GS1.CSSM.XMLGenerate.WebService.ServiceAuthenticator, GS1.CSSM.XMLGenerate.WebService"/>
</serviceCredentials>
</behavior>
<behavior name="noAuthentication">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!--<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>-->
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
This is the Container Setup :
var container = new WindsorContainer();
container.AddFacility()
.Register(
Component.For<IXMLGenerateService>()
.ImplementedBy<XMLGenerateServiceClient>()
.AsWcfClient(
new DefaultClientModel
{
Endpoint =
WcfEndpoint.FromConfiguration("wsSecureService")
}.Credentials(new UserNameCredentials("zul", "password"))));
And this is client config file :
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="wsSecureService">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:44302/Service/XMLGenerateService.svc" binding="wsHttpBinding" bindingConfiguration="wsSecureService" contract="XMLGenerateService.IXMLGenerateService" name="wsSecureService" />
</client>
</system.serviceModel>
I got this error "Additional information: The username is not provided. Specify username in ClientCredentials." once I tried to call method from the service.
Any ideas?
I will answer it by myself :)
here it is how i resolved that issue
container.Kernel.AddFacility<WcfFacility>()
.Register(Component.For<IXMLGenerateService>()
.AsWcfClient(new DefaultClientModel
{
Endpoint = WcfEndpoint.FromConfiguration("wsSecureService")
}.Credentials(new UserNameCredentials("zul", "password"))));
_smXMLGenerateService = container.Resolve<IXMLGenerateService>();
Hopefully, it can help anyone with the same issue.
I have one wcf service on this site http://wswob.somee.com/wobservice.svc
I try to consume that service with my winform app. This is the error I receive when I create an instant of the service
com.somee.wobservice.IwobserviceClient myservice = new com.somee.wobservice.IwobserviceClient();
error:
Could not find default endpoint element that references contract
'com.somee.wobservice.Iwobservice' in the ServiceModel client configuration section. This
might be because no configuration file was found for your application, or because no
endpoint element matching this contract could be found in the client element.
I searched and modified my app.config file:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="wobservice">
<clientVia />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint
name="wobservice"
address="http://wswob.somee.com/wobservice.svc"
binding="webHttpBinding"
contract="com.somee.wobservice"
behaviorConfiguration="wobservice" />
</client>
</system.serviceModel>
</configuration>
And my web.config in wcf folder:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://wswob.somee.com/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<bindings>
<webHttpBinding>
<binding>
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
<add binding="basicHttpBinding" scheme="http"/>
</protocolMapping>
<services>
<service name="wobwcf.wobservice">
<endpoint address=""
binding="webHttpBinding"
behaviorConfiguration="Web"
contract="wobwcf.Iwobservice" />
</service>
</services>
</system.serviceModel>
I don't really sure which part I got wrong. My experience of wcf is just a week...
Copy system.serviceModel section from the app.config in your library project and put it in your web.config and refresh service reference. See also this answer. Could not find default endpoint element
Add "WSHttpBinding" end point in your WCF service web.config file like below
<endpoint address="web" behaviorConfiguration="jsonBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="DataService.IDataService"/>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="DataService.IDataService" />
and in your app.config file write code like below
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDataService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/pricedataservice/DataService.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IDataService" contract="DataService.IDataService"
name="WSHttpBinding_IDataService" />
</client>
I am sure this will fix your problem and below blog will help you to understand different type of binding in WCF service
http://www.dotnet-tricks.com/Tutorial/wcf/VE8a200713-Understanding-various-types-of-WCF-bindings.html
Add client definition in your client web.config file like below;
<system.serviceModel>
/////
<client>
<endpoint address="referencedurl"
binding="webHttpBinding" bindingConfiguration=""
contract="MemberService.IMemberService"
name="MemberServiceEndPoint"
behaviorConfiguration="Web">
</endpoint>
</client>
////
</system.serviceModel>
AND Service Reference Name must same as the Interfaces prefix. contract="ReferenceName.IMemberService"
i have deployed my wcf service on IIS.. Its giving me this error when I want to access its one of method "EndPoint Not Found" While locally its working fine for me and returning me data.
Here is my Web.config Bindings Information
<system.webServer>
<directoryBrowse enabled="false" />
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="RTAService" behaviorConfiguration="WtfServiceBehaviour">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="wtfSslBinding" behaviorConfiguration="WebHttpBehaviour" contract="IRTAService" />
<endpoint address="soap" binding="basicHttpBinding" contract="IRTAService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="wtfSslBinding" />
<binding name="streamedBinding"
maxBufferSize="65536"
maxReceivedMessageSize="2000000000"
transferMode="Streamed">
<readerQuotas maxDepth="500000000"
maxArrayLength="500000000" maxBytesPerRead="500000000"
maxNameTableCharCount="500000000" maxStringContentLength="500000000"/>
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WebHttpBehaviour">
<webHttp helpEnabled="true" defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json"
automaticFormatSelectionEnabled="false" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WtfServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Please tell me any work around for that.
I dont see endpoint defined any where . Your config should have something like this.`
<endpoint address="http://localhost:57800/Services.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IServices" contract="MYServices.IServices"
name="BasicHttpBinding_IServices" />
I developed a WCF in a Managed Windows Service, based on this tutorial
This is how my interface are defined :
namespace HomeAutomationWindowsService
{
[ServiceContract]
public interface IHomeAutomation
{
[OperationContract]
string connect();
[OperationContract]
Boolean sendAction(string address, string command);
}
}
And my App.config file is like this :
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Unsecured">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="HomeAutomationWindowsService.HomeAutomationService"
behaviorConfiguration="HomeAutomationServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://192.168.11.178:8000/service"/>
</baseAddresses>
</host>
<!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/service -->
<endpoint address=""
contract="HomeAutomationWindowsService.IHomeAutomation"
binding="wsHttpBinding"
bindingConfiguration="Unsecured" />
<!-- the mex endpoint is explosed at http://192.168.11.178:8000/ mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="HomeAutomationServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
When I make a call from a Console or a WPF App I can see the public methods, but when I do it using Windows Phone I can't see anything.
What I should do to make my WCF or Windows Phone communicating together.
I think WsHttpBinding is not supported by WP7. Try using BasicHttpBinding:
Web.config:
<system.serviceModel>
<services>
<service name="MyProject.MyService" behaviorConfiguration="behavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="binding" contract="MyProject.MyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="binding">
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
After adding the webservice to your WP7 project (add service reference) the ServiceReferences.ClientConfig should look like (adding web service with WsHttpBinding generates an empty file):
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_DataService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
</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>