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>
Related
I've been looking online but I can't find a defined procedure or an example on how to configure a basicHTTP self-hosted WCF service to compress messages that servers sends to clients.
I would like to use GZIP or similar technology.
this is my application app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<services>
<service name="Application.ApplicationServicesProxy" behaviorConfiguration="ApplicationSvcsBehave">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9001/ApplicationSvcs"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:9001/ApplicationSvcs" binding="basicHttpBinding" contract="Application.IApplicationServices"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ApplicationSvcsBehave">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
This is how I create the service:
var host = new ServiceHost(typeof(ApplicationServicesProxy));
host.Open();
Services are defined in IApplicationServices that is inherited by ApplicationServicesProxy
[ServiceContract]
interface IApplicationServices
{
[OperationContract]
string[] MethodOne();
}
public class AppicationServicesProxy : IApplicationServices
{
public string[] MethodOne()
{
// return a string value;
}
}
And this is how I connect the client to the service
var ApplicationSvcs = new ApplicationSvcs.ApplicationServicesClient("BasicHttpBinding_IApplicationServices");
I am currently using .NET 4.8
I solved doing like this, message size went down fromm 300 Kb/s to 11 Kb/s so it really works and CPU is not very interested in that:
<system.serviceModel>
<services>
<service name="Application.ApplicationServicesProxy" behaviorConfiguration="ApplicationSvcsBehave">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9001/ApplicationSvcs"/>
</baseAddresses>
</host>
<endpoint address="" binding="customBinding" bindingConfiguration="BinaryCompressionBinding" contract="Application.IApplicationServices"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ApplicationSvcsBehave">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="BinaryCompressionBinding">
<binaryMessageEncoding compressionFormat ="GZip"/>
<httpTransport decompressionEnabled="true"/>
</binding>
</customBinding>
</bindings>
</system.serviceModel>
and on client side
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_IApplicationServices" >
<binaryMessageEncoding compressionFormat="GZip"/>
<httpTransport maxReceivedMessageSize="20000000"/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:9001/ApplicationSvcs" binding="customBinding"
bindingConfiguration="CustomBinding_IApplicationServices" contract="ApplicationSvcs.IApplicationServices"
name="CustomBinding_IApplicationServices" />
</client>
</system.serviceModel>
SOAP messages can be very heavy but in my application I could not use REST so I hope that can be of any help.
I have recently a new exception. When I try to call a method with a byte array in parameter I get a 413 error.
I try to change maxBufferSize, maxReceivedMessageSize and maxBufferPoolSize but nothing had changed.
In my app.config of my application I have :
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="soap"
maxReceivedMessageSize="1116553600"
maxBufferPoolSize="1116553600"
maxBufferSize="1116553600"/>
</basicHttpBinding>
<wsHttpBinding>
<binding name="mex" maxReceivedMessageSize="1116553600"
maxBufferPoolSize="1116553600">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:9804/ServiceBX.svc/soap"
binding="basicHttpBinding" bindingConfiguration="soap" contract="ServiceReferenceBX.ServiceBX"
name="soap" />
</client>
</system.serviceModel>
And in my web.config of my WCF service I have :
<system.serviceModel>
<services>
<service name="BXSportWCFLib.ServiceBX" behaviorConfiguration="MyServiceBehavior">
<endpoint name="rest" address="" binding="webHttpBinding" contract="BXSportWCFLib.ServiceBX" behaviorConfiguration="restBehavior" />
<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="BXSportWCFLib.ServiceBX" />
<endpoint name="soap" address="soap" binding="basicHttpBinding" contract="BXSportWCFLib.ServiceBX" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
I see lot of things on this error but anything I try don't work.
First I like to know in wich file I must modify ?
I try to add bindings and modify my endoint but now when I execute my application I had a : "The requested service can't be activated"
<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>
<bindings>
<basicHttpBinding>
<binding name="soap"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="116553600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="web"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="11653600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="BXSportWCFLib.ServiceBX" behaviorConfiguration="MyServiceBehavior">
<endpoint name="rest"
address=""
binding="webHttpBinding"
bindingConfiguration="web"
contract="BXSportWCFLib.ServiceBX"
behaviorConfiguration="restBehavior" />
<endpoint name="soap"
address="soap"
binding="basicHttpBinding"
bindingConfiguration="soap"
contract="BXSportWCFLib.ServiceBX" />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetaDataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior" >
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Thanks
It sounds like you're receiving the error when calling the service, so you need to fix the config file for the service, not the client.
The posted config for the service does not specify any binding configurations, so WCF will use the default settings for the specified values. You need to a) define the binding configurations you want to use and b) assign them to the endpoints. Failure to do both will result in WCF still using the default values.
In your service config, add the following in the <system.serviceModel> section:
<bindings>
<basicHttpBinding>
<binding name="soap"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="116553600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</basicHttpBinding>
<webHttpBinding
<binding name="web"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="11653600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</webHttpBinding>
</bindings>
Note that you need to specify the configuration for both basicHttpBinding and webHttpBinding.
Next, assign them to the correct endpoints via the bindingConfiguration attribute on the <endpoint> element:
<endpoint name="rest"
address=""
binding="webHttpBinding"
bindingConfiguration="web"
contract="BXSportWCFLib.ServiceBX"
behaviorConfiguration="restBehavior" />
<endpoint name="soap"
address="soap"
binding="basicHttpBinding"
bindingConfiguration="soap"
contract="BXSportWCFLib.ServiceBX" />
Thirdly, your mex endpoint is specifying the wrong contract - it should be IMetaDataExchange:
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetaDataExchange" />
If you still get the 413 error, you will also want to adjust the maxRequestLength in <httpRuntime> element. This goes in the config file in the <system.webServer> section:
<system.web>
<httpRuntime maxRequestLength="116533600" />
</system.web>
the default for maxRequestLength is 4 MB, but most likely the issue is with the values being used for the bindings on your service.
The solution work !
I had add bindings but I change the IMetaDataExchange and write BXSportWCFLib.ServiceBX and I have not the message "The requested service can't be activated"
<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>
<bindings>
<basicHttpBinding>
<binding name="soap"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="116553600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="web"
maxReceivedMessageSize="116553600"
maxBufferPoolSize="11653600"
maxBufferSize="116553600">
<readerQuotas maxStringContentLength="116533600" />
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="BXSportWCFLib.ServiceBX" behaviorConfiguration="MyServiceBehavior">
<endpoint name="rest"
address=""
binding="webHttpBinding"
bindingConfiguration="web"
contract="BXSportWCFLib.ServiceBX"
behaviorConfiguration="restBehavior" />
<endpoint name="soap"
address="soap"
binding="basicHttpBinding"
bindingConfiguration="soap"
contract="BXSportWCFLib.ServiceBX" />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetaDataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior" >
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
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"
Getting the following error when attempting to start a Windows service hosting a WCF service:
Could not find a base address that matches scheme net.msmq for the endpoint with binding NetMsmqBinding. Registered base address schemes are [http].
Works fine if I remove the netmsmq binding and use the basichttp binding. Config is as below:
<system.serviceModel>
<services>
<service name="ManageContactService.ManageContact" behaviorConfiguration="ContactServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8888/ManageContact/ContactService"/>
</baseAddresses>
</host>
<endpoint address="net.msmq//localhost/private/testqueue" binding="netMsmqBinding"
bindingConfiguration="MyMsmqBinding" contract="ManageContactService.IManageContact" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netMsmqBinding>
<binding name="MyMsmqBinding">
<security mode="None"></security>
</binding>
</netMsmqBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ContactServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
You need a colon:
net.msmq://localhost/private/testqueue
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>