WCF service method call time grows - c#

Setup is mono latest stable on raspberry pi, polling data from service on server with .NET 4.5.
My configuration for server side:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="vlcBehaviour">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="ser.Serwys">
<endpoint address="net.tcp://192.168.56.1:9070/WindowService" binding="netTcpBinding" bindingConfiguration="AnonymousTcpBinding"
contract="Window.Service.IWindowServiceHost" />
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="AnonymousTcpBinding" receiveTimeout="00:00:01"
sendTimeout="00:00:01"
maxBufferSize="1000"
maxConnections="100"
maxBufferPoolSize="100"
listenBacklog="200"
maxReceivedMessageSize="1000">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
On client side:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="maxItems">
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="AnonymousTcpBinding" openTimeout="00:00:01" receiveTimeout="00:00:01" sendTimeout="00:00:01" maxBufferSize="1000" maxConnections="200" listenBacklog="200" maxReceivedMessageSize="1000">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint name="WindowService" address="net.tcp://192.168.56.1:9070/WindowService" binding="netTcpBinding" bindingConfiguration="AnonymousTcpBinding" contract="Window.Service.IWindowServiceHost" />
</client>
</system.serviceModel>
Service contract:
namespace Window.Service
{
[ServiceContract(
Namespace = "http://window",
Name = "WindowHost")]
public interface IWindowServiceHost
{
[OperationContract]
void Connect(int windowId);
[OperationContract]
void Disconnect();
[OperationContract]
DisplayData GetData();
}
}
Implementation of service:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
public class Serwys:IWindowServiceHost
Method that is called:
public DisplayData GetData()
{
Console.WriteLine("Called get data {0}:{1}:{2}",DateTime.Now.Minute,DateTime.Now.Second,DateTime.Now.Millisecond);
return new DisplayData
{
BoxesInProgress = 1,
};
}
Call to GetData from client takes more and more time, don't know why.
I have tested it on Ubuntu also, Mono is latest version here how I log it:
Stopwatch stp = new Stopwatch();
stp.Start();
var data = remote.GetData();
stp.Stop();
log.WarnFormat("Polling service took: {0} ms", stp.ElapsedMilliseconds);
Any explanations?? I think it is Mono bug, because setup is really basic no concurrency method called is dead simple, and polling times are going up.
I call it on timer elapse, and for test I call it every 10ms but it is growing even if I call it every second, but slower, and this only gives me more time before all crashes.

Related

WCF: There was no endpoint listening at, that could accept the message

I have WCF Service (JSON), and ASP.NET website that we add a service reference to that site connected to the wcf service.
when i test the service using POSTMAN and SOAPUI and also when i try the following code:
WebClient client = new WebClient();
client.Headers["Content-type"] = "application/json";
client.Encoding = System.Text.Encoding.UTF8;
string result = client.UploadString("http://localhost:1122/Service.svc/GetInfo", string.Empty);
It works fine (note that all my service functions are POST).
But when i add the service to service reference an connect to the service and try to call the function GetInfo(), the following issue appears.
Exception Message
There was no endpoint listening at http://localhost:1122/Service.svc that could
accept the message. This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details.
Inner Exception Message
The remote server returned an error: (404) Not Found.
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
I think this issue is due to incorrect configuration on the config file for the webservice and website, so you can find below both config files:
Webservice Config File:
<system.serviceModel>
<services>
<service name="WCFService.Service" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="WCFService.IService" name="WebHttp_IService"
bindingConfiguration="WebHttpBinding_IService" behaviorConfiguration="ServiceBehaviorEndpoint" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding_IService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647" openTimeout="00:20:00" receiveTimeout="00:20:00" closeTimeout="00:20:00" sendTimeout="00:20:00">
<readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="ServiceBehaviorEndpoint">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Website Config File:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService"/>
</basicHttpBinding>
<webHttpBinding>
<binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1122/Service.svc" bindingConfiguration="BasicHttpBinding_IService"
contract="WCFServices.IService" name="BasicHttpBinding_IService" binding="basicHttpBinding" />
</client>
</system.serviceModel>
Note that the Service Reference name in the Website is WCFService, and we try to host the service to the iis with public IP and open the firewall, but the same issue appears.
When we invoke the service which created with WebHttpBinding via client proxy class, there may be some differences from other bindings. We need to configure the client configuration manually, such as adding the endpoint behavior to service endpoint and webget/webinvoke attribute to the automatically generated operation method by adding service reference.
I have made a demo, wish it is useful to you.
Server end (console application).
class Program
{
static void Main(string[] args)
{
using (ServiceHost sh=new ServiceHost(typeof(MyService)))
{
sh.Opened += delegate
{
Console.WriteLine("Service is ready......");
};
sh.Closed += delegate
{
Console.WriteLine("Service is closed");
};
sh.Open();
Console.ReadLine();
sh.Close();
}
}
}
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet]
string SayHello();
}
public class MyService : IService
{
public string SayHello()
{
return "Hello, Busy world"; }
}
App.config
<system.serviceModel>
<services>
<service behaviorConfiguration="Service1Behavior" name="VM1.MyService">
<endpoint address="" binding="webHttpBinding" contract="VM1.IService" behaviorConfiguration="rest" >
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:13008"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="rest">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Client(console app)
static void Main(string[] args)
{
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
try
{
Console.WriteLine(client.SayHello());
}
catch (Exception)
{
throw;
}
}
App.config
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="rest">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://10.157.13.69:13008/" binding="webHttpBinding" contract="ServiceReference1.IService" behaviorConfiguration="rest">
</endpoint>
</client>
</system.serviceModel>
We also need to add the WebGet attribute to the operation method.
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] [System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference1.IService")]
public interface IService {
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/SayHello", ReplyAction="http://tempuri.org/IService/SayHelloResponse")]
[WebGet]
string SayHello();
Result.
Feel free to let me know if there is anything I can help with.

Can't get file size when loading from WCF service host by web browser

I have some test WCF service with streamed webHttpBinding, which allows to download files by web browser. The problem is browser doesn't show file size and download progress.
This is the service contract:
[ServiceContract]
public interface IDataTransferService
{
[WebGet(UriTemplate = "download?file={fileName}")]
Stream GetDownloadStream(string fileName);
}
This is the service implementation:
public sealed class DataTransferService : IDataTransferService
{
public Stream GetDownloadStream(string fileName)
{
var context = WebOperationContext.Current;
var stream = File.OpenRead(fileName);
WebOperationContext.Current.OutgoingResponse.Headers["Content-Disposition"] = $"attachment; filename={Path.GetFileName(fileName)}";
WebOperationContext.Current.OutgoingResponse.ContentType = "application/octet-stream";
WebOperationContext.Current.OutgoingResponse.Headers["Content-Length"] = stream.Length.ToString();
return stream;
}
}
And this is the service configuration:
<system.serviceModel>
<services>
<service name="WcfStreamingTest.Server.DataTransferService">
<endpoint contract="WcfStreamingTest.IDataTransferService"
address="http://localhost:8000/streamingtest/api/transfer"
binding="webHttpBinding"
bindingConfiguration="streamedWeb"
behaviorConfiguration="web"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="streamedWeb" transferMode="Streamed" sendTimeout="00:15:00" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
Name of file shows correctly, but information about file size is missing.
Try to change transferMode to StreamedResponse
<binding name="streamedWeb" transferMode="StreamedResponse" sendTimeout="00:15:00" />

How to call a service using multiple Endpoint URIs

To put into context, I have a client application that will attempt to call a webservice that will be deployed on multiple web servers. The URI list will be obtained from the Settings.settings file of the client and a foreach loop will cycle through the URIs until the available service responds.
Let's say I have a service with the following contract:
[ServiceContract]
public interface ICMMSManagerService
{
[OperationContract]
ServerInfo GetServerInfo(string systemNumber);
}
In the web.config of the service's project, I have defined CMMSManager service with the the endpoint name: BasicHttpBinding_IWorkloadMngrService
<system.serviceModel>
<services>
<service name="WorkloadMngr">
<endpoint binding="basicHttpBinding" contract="IMetadataExchange" />
</service>
<service name="CMMSManager">
<endpoint binding="basicHttpBinding" contract="IMetadataExchange" name="BasicHttpBinding_IWorkloadMngrService" />
</service>
</services>
<client>
<remove contract="IMetadataExchange" name="sb" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
On the client side, I have the following code executed when the application starts:
private void QueryWebServiceUrls()
{
var webServiceUrls = Properties.Settings.Default.WebServiceUrls;
foreach (var webServiceUrl in webServiceUrls)
{
try
{
var client = new CMMSManagerServiceClient("BasicHttpBinding_IWorkloadManagerService");
client.Endpoint.Address = new EndpointAddress(new Uri(webServiceUrl),
client.Endpoint.Address.Identity, client.Endpoint.Address.Headers);
client.Open();
var result = client.GetServerInfo("test");
}
catch (EndpointNotFoundException e)
{
continue;
}
catch (InvalidOperationException e)
{
break;
}
}
}
But the application crashes with an InvalidOperationException when the CMMSManagerServiceClient class is instanciated.
Could not find endpoint element with name
'BasicHttpBinding_IWorkloadMngrService' and contract
'ComClientService.ICMMSManagerService' 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 name could be found in the client element.
I have the following configuration in the app.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICMMSManagerService">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/WorkloadMngr/CMMSManagerService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICMMSManagerService"
contract="ComClientService.ICMMSManagerService" name="BasicHttpBinding_ICMMSManagerService" />
</client>
</system.serviceModel>
I thought everything was valid by passing the BasicHttpBinding_ICMMSManagerService parameter to the CMMSManagerServiceClient class. I have no clue what am I missing at the moment... Any ideas?
The error is telling you exactly what's wrong: there is no endpoint with the name BasicHttpBinding_IWorkloadMngrService. The app.config says the endpoint is called BasicHttpBinding_ICMMSManagerService so your code should be:
var client = new CMMSManagerServiceClient("BasicHttpBinding_ICMMSManagerService");
Hope this helps.

Using Net.TCP WCF in IIS

I am trying to setup a NetTCP WCF service.
This is my server code:
iSync.cs:
[ServiceContract]
public interface ISync
{
[OperationContract(IsOneWay = true)]
void UploadMotionDynamic(byte[] jpegStream, string alias, Int16 camIndex, byte[] motionLog, double mul, byte isLive, byte doIsave);
}
Sync.cs:
public class Sync : ISync
{
public void UploadMotionDynamic(byte[] jpegData, string alias, Int16 camIndex, byte[] motionLog,double mul,byte isLive, byte doIsave)
{
//do stuff
}
}
web.config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NetTCPBehaviour">
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="65536" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Sync" behaviorConfiguration="NetTCPBehaviour">
<endpoint address="net.tcp://localhost:8888/Sync" binding="netTcpBinding" contract="ISync" name="wsSyncerMotion" bindingConfiguration="NetTCPBindingEndPoint"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="NetTCPBindingEndPoint" sendTimeout="00:01:00">
<security mode="None" />
</binding>
</netTcpBinding>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Now it cannot be the port being blocked because I even tested it by turning off the firewall.
I have made sure 'Net Tcp Listener Adaptor' is running in my
services.
I have added net.tcp in my IIS\Advanced Settings| Enabled
Protocols.
I have added the Non-HTTP activation setting in .NET
Features.
I have followed the links kindly supplied by people here.
The error I get (now) is:
(I cannot seem to enlarge this image with viewing in a different tab)

WCF service returning "is undefined" in JavaScript

When this JavaScript code is run, it tells me that "0x800a1391 - JavaScript runtime error: 'InputService' is undefined".
I have tried and tried, and I just can't seem to figure out of what I am missing...
Web.Config file (just the web service part):
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="CommonEndPointBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="InputService">
<endpoint name="" address="" behaviorConfiguration="CommonEndPointBehavior" binding="webHttpBinding" contract="InputService" bindingConfiguration="webBinding" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<!--<security mode="Transport">-->
<security mode="None"/>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
The Service:
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class InputService
{
[OperationContract]
public string EditSiteElement(int siteid, string name, string url, string description, int siteorder, bool active)
{
return Input.EditSiteElement(siteid, name, url, description, siteorder, active);
}
}
The references in the web form:
scriptManagerProxy.Services.Add(new ServiceReference("~/User/Input.svc"));
scriptManagerProxy.Scripts.Add(new ScriptReference("~/User/Input.js"));
JavaScript file:
//When edit button is clicked on row.
function EditSiteElement(siteid) {
InputService.GetSiteIdInfo(siteid, function (result) {
var stuff = result.split('ยค');
$('[id$=TextBox_name]').val(stuff[0]);
$('[id$=TextBox_link]').val(stuff[1]);
$('[id$=TextBox_description]').val(stuff[2]);
$('[id$=CheckBox_active]').prop('checked', (stuff[3] == 'True'));
$('[id$=TextBox_order]').val(stuff[4]);
//Open the dialog
$("[id$=panel_Input]").dialog('open');
SiteIdForSave = siteid;
});
}
So, there are a couple of changes you have to do.
First, decorate the service method with the WebInvoke attribute which resides in the System.ServiceModel.Web namespace (you may have to add the reference to your project).
[OperationContract]
[System.ServiceModel.Web.WebInvoke] //add this attribute
public string EditSiteElement(int siteid, string name, string url, string description, int siteorder, bool active)
{
return Input.EditSiteElement(siteid, name, url, description, siteorder, active);
}
Second, in the InputService.svc file (in Visual Studio, right click on the InputService.svc file and select View Markup), add the Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" attribute:
<%# ServiceHost Language="C#" Debug="true" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" Service="WebApplication6.InputService" CodeBehind="InputService.svc.cs" %>
Make sure that the target framework version for your application is 4.5.
[EDIT]
I suggest you modify the web.config's <system.serviceModel> section as follows. Please pay attention to the use of your namespaces (MyNamespace) and to the fact that I moved the behavior definition from the end point to the service level.
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="InputServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service behaviorConfiguration="InputServiceBehavior" name="MyNamespace.InputService">
<endpoint address="" binding="webHttpBinding" contract="MyNamespace.InputService" bindingConfiguration="webBinding"/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webBinding">
<!--<security mode="Transport">-->
<security mode="None"/>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>

Categories

Resources